hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Roland Weber <ossf...@dubioso.net>
Subject Re: [help] how to set an OutputStream to a POST request?
Date Sun, 02 Mar 2008 13:45:33 GMT
Hi Micky,

>> What _do_ you get at the server via Reader/InputStream?
> I get "null" via Reader/InputStream.

That is interesting, considering your sample code below.

> Here are part codes of the client side and server side I used for experimenting.
> 
> ---- client code ----
> // ... lots of construction 
> StringEntity stringEntity = new StringEntity(login, HTTP.UTF_8);    // login is an xml
content

// let's see what is being sent
System.out.println("posting the following string: " + login);

> stringEntity.setContentType(" text/plain; charset=UTF-8");
> httpPost.setEntity(stringEntity);
> httpclient.execute(httpPost);


This fragment of your client side code looks correct.
I'm just wondering about the value of login. Have you
tried sending a hard-coded string instead?
...StringEntity("<?xml version='1.0' encoding='UTF-8'?><empty/>", HTTP.UTF_8);


> ---- server code ----
> // ... lots of construction
> //build reader to read input buffer
> BufferedReader reader = request.getReader();
> StringBuffer buffer = new StringBuffer();
> 			
> int c ;
> while( (c = reader.read()) != -1){
> 	buffer.append( (char)c );
> }
> reader.close();
> 
> System.out.println("receive: " + buffer.toString());
> ----
> 
> The buffer.toString() is null.

Now that is interesting. If the reader were null, you'd get
a NullPointerException in the while() loop. If the buffer
was empty, you'd see "receive: " without a null. The return
value of buffer.toString is never null. If you are seeing
"receive: null", then you are actually sending the string
"null" in your POST request to the server.

See the comments above: check the string you are sending.

cheers,
   Roland


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Mime
View raw message