So I checked few thing further.
Problem is only when there is an error generated from the API. For positive,
it works fine.
InputStreamEntity reqEntity = null;
try {
reqEntity = new InputStreamEntity(new
FileInputStream(file), -1);
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
if (reqEntity != null) {
reqEntity.setContentType("application/xml");
reqEntity.setChunked(true);
}
httppost.setEntity(reqEntity);
System.out.println("executing request " +
httppost.getRequestLine());
ResponseHandler<String> responseHandler = new
BasicResponseHandler();
String responseBody = null;
try {
responseBody = httpclient.execute(httppost,
responseHandler);
} catch (org.apache.http.client.HttpResponseException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
When we get an exception, I would like to see the response XML in that case
as well.
What can I do?
Regards
Ajay
-----Original Message-----
From: Ajay Bansal [mailto:[email protected]]
Sent: Wednesday, January 13, 2010 4:26 PM
To: 'HttpClient User Discussion'
Subject: help with httppost response
Hi All,
I am using 4x APIs. Here is my code
=========================
String baseServer = "http://localhost:8080";
String serverUrl = baseServer + Some API URL;
String signature = genSig.getSignature();
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(serverUrl);
httppost.setHeader(Sets the header);
File file = new File("data/userRegister.xml");
InputStreamEntity reqEntity = new InputStreamEntity(
new FileInputStream(file), -1);
reqEntity.setContentType("application/xml");
reqEntity.setChunked(true);
httppost.setEntity(reqEntity);
System.out.println("executing request " +
httppost.getRequestLine());
HttpResponse response = httpclient.execute(httppost); /*
THIS CODE WORKS FINE - I see the REQUEST in the backend */
/* Problem is I am not able to capture the response using following code.
What do I need to do? */
HttpEntity resEntity = response.getEntity();
System.out.println("Status : " + response.getStatusLine());
if (resEntity != null) {
System.out.println("Response content length: "
+ resEntity.getContentLength());
/* I always get this as -1*/
System.out.println("Chunked?: " +
resEntity.isChunked());
}
if (resEntity != null) {
resEntity.consumeContent();
}
===============================
I need to print the response that I get from the above method. How do I do
that?
Regards
Ajay
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]