commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Becke <>
Subject Re: [HttpClient] Can't even Post Data
Date Tue, 29 Jun 2004 10:55:55 GMT
Hi Andrew,

I believe the problem occurs because you are setting the content type.  
PostMethod.addParameter() form URL encodes the given value and includes 
it in the post body.  For this to work correctly it needs to set the 
content type accordingly.  Since you are setting the content type 
manually HttpClient assumes you are doing it correctly and does not 
overwrite it.  My guess is that if you don't set the content type, all 
will be well.


On Jun 28, 2004, at 1:35 AM, Andrew van der Voort wrote:

> Hi. I'm sure I'm doing something wrong, but don't know what...
> I have an applet that communicates with a J2EE server. It's going OK 
> with
> classes but I am wanting to see if I can make the thing more
> robust with the HttpClient package.
> We send up a stream of data, which the server reads, assembles into
> meaningful data for it, and acts upon it. Usually it returns another
> similarly formatted stream of data in return.
> Here's what I'm doing:
> HttpClient httpClient = new HttpClient();
> PostMethod method = new PostMethod(completeURL);
> method.setRequestHeader("Content-type", "text/xml; charset=UTF-8");
> method.addParameter( "toServer", requestData.getText() );
> int statusCode = -1;
> try
> {
>   statusCode = httpClient.executeMethod( method );
> }
> catch (HttpRecoverableException e)
> .
> .
> .
> However when I get to the server, request.getParameter("toServer") is 
> null,
> so the data isn't getting sent up. What's wrong with what I've done? 
> I've
> seen a few posts that say "use setRequestBody()" but that seems like a
> cop-out. I have a parameter, I've set it, why isn't it being sent?
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> For additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message