Java HttpPost no response

Showing 1-3 of 3 messages
Java HttpPost no response Martin Kondov 4/13/12 8:42 AM
I am getting an "OK" status,but no XML content in the response.
Using HttpClient API for Java.

HttpPost post= new HttpPost("https://MYLOGIN.freshbooks.com/api/2.1/
xml-in
");
System.out.println(post.getRequestLine());
StringEntity se = new StringEntity("<request method=\"system.current
\"></request>","UTF-8");

se.setContentType("text/xml");
post.setHeader("Content-Type","application/x-www-form-urlencoded");
post.setEntity(se);

HttpResponse response = httpclient.execute(post);
System.out.println(response.getProtocolVersion());
System.out.println(response.getStatusLine().getStatusCode());
System.out.println(response.getStatusLine().toString());

HttpEntity entity = response.getEntity();
                if (entity != null) {
                    InputStream instream = entity.getContent();
                    System.out.println(instream.toString());
                    }
                }

Output in console:

HTTP/1.1 200 OK
org.apache.http.conn.EofSensorInputStream@17e845a


Please,somebody tell me what I am missing. :(

Re: Java HttpPost no response Martin Kondov 4/13/12 8:44 AM
Forgot to mention that this code foolows the HttpClient connection and
the connection is established successfully (as the 200 "OK" code
signifies).
Re: Java HttpPost no response Martin Kondov 4/13/12 10:06 AM
Nevermin,I figured it out.For those who want the solution:

HttpResponse response = httpclient.execute(post);
String content = EntityUtils.toString(entity);
System.out.println(content);

is the proper way to gather the response...

I would appreciate if somebody shed some light on the subject.In
particular,why my method did not work and why do we must use
EntityUtils to parse the entity...isn't the response send as standard
xml?