commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Andrew van der Voort" <>
Subject RE: [HttpClient] Can't even Post Data
Date Tue, 29 Jun 2004 20:32:34 GMT
Hi Mike, thanks for that. 

After much trial and error I found out the same thing yesterday. Not the
reason why, just that removing the content type header made it work...

My next problem was that I couldn't get the session id to stick. Using the classes I was getting the header value "Set-Cookie" and giving it
back to the next request by setting a request property of "Cookie". I tried
that same with HttpClient but it didn't work, but then I found out about
HttpState, so that's resolved.

The next problem to solve:
When I inherited the applet, it's communication protocol consisted of
breaking down java objects into a stream using a custom protocol to
separate fields, objects etc. This is transmitted over the wire and
reconstructed at the other end. I am part way through converting that to
use java's ability to stream objects itself so that I can just construct
objects and let java stream them. It's not entirely clear to me how to go
about using HttpClient to stream java objects as opposed to text/html. 

Any clues there?

Thanks, Andrew

>-----Original Message-----
>From: Michael Becke []
>Sent: Tuesday, 29 June 2004 10:56 p.m.
>To: Jakarta Commons Users List
>Subject: Re: [HttpClient] Can't even Post Data
>Hi Andrew,
>I believe the problem occurs because you are setting the 
>content type.  
>PostMethod.addParameter() form URL encodes the given value and 
>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:

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

View raw message