This week's book giveaways are in the AI and JavaScript forums.
We're giving away four copies each of GANs in Action and WebAssembly in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of GANs in ActionE this week in the AI forum
or WebAssembly in Action in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Joe Ess
  • salvin francis
  • fred rosenberger

Http Client Component

Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the best Http Client component for a java application to communicate with a remote web server .Basically we are trying to submit info to a webportal server programatically and get the response back from that remote server.
Thanks in advance
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the class doesn't do what you want, try the Apache Jakarta HttpClient.
- Peter
surya thandra
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply.
I tried using the HTTP Clinet Component from Apache Iam getting the following errors.
My Code:
org.apache.commons.httpclient.Header CONTENT_TYPE = new org.apache.commons.httpclient.Header("Content-Type","text/html");
org.apache.commons.httpclient.HttpClient client=new org.apache.commons.httpclient.HttpClient();
//org.apache.commons.httpclient.HttpConnection con=new org.apache.commons.httpclient.HttpConnection("portal.cpn.vwg",);
//org.apache.commons.httpclient.HttpState httpState= new org.apache.commons.httpclient.HttpState();
org.apache.commons.httpclient.methods.PostMethod post = new org.apache.commons.httpclient.methods.PostMethod();
post.setFollowRedirects(true); url=new"");
org.apache.commons.httpclient.NameValuePair form_data[] = new org.apache.commons.httpclient.NameValuePair[4];

form_data[0] = new org.apache.commons.httpclient.NameValuePair("language", "2");
form_data[1] = new org.apache.commons.httpclient.NameValuePair("user","amndsmndjn");
form_data[2] = new org.apache.commons.httpclient.NameValuePair("dealer","jnjfbvjf");
form_data[3] = new org.apache.commons.httpclient.NameValuePair("password","vfjbvfS");


org.apache.commons.httpclient.Header resp[] =post.getResponseHeaders();

for(int i=0;i<resp.length;i++){

final String strGetResponseBody =post.getResponseBodyAsString();
Server: Microsoft-IIS/4.0
HTTP/1.1 405 Method not allowed
Server: Microsoft-IIS/4.0
Date: Fri, 06 Dec 2002 22:58:06 GMT
Connection: close
Content-Length: 545
Content-Type: text/html
<html><head><title>Error 405</title>
<meta name="robots" content="noindex">
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1"></head>
<h2>HTTP Error 405</h2>
<p><strong>405 Method Not Allowed</strong></p>
<p>The method specified in the Request Line is not allowed for the resource identified by the request. Please ensure that you have the proper MIME type set up for the resource you are requesting.</p>
<p>Please contact the server's administrator if this problem persists.</p>
I was able to do this succesfully with other HTTP clinets ,but we have to go with Apache.
Any Suggestions Appreciated.
Ranch Hand
Posts: 168
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use GetMethod instead of PostMethod.
Also, this code

doesn't look right. You can set the querystring as either a String or an array NameValuePair[], but not both. The ?language= is part of the querystring. Try
surya thandra
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Mike,
I have correcedted that Query String.I got a Error Code 400 Bad syntax in request.
Here i need to post some form data and get the response back.I was able to achieve this by Post using Innovation API but we have it do it by apache.
Suggestions appreciated.
What do you have in that there bucket? It wouldn't be a tiny ad by any chance ...
Java file APIs (DOC, XLS, PDF, and many more)
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!