hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ajay Bansal <ajay.bansa...@gmail.com>
Subject Re: help with httppost response
Date Thu, 14 Jan 2010 06:52:11 GMT
Thanks :)

In the meanwhile i proceeded with HttpURLConnection. Once the API call
fails, I get IOException and
InputStreamReader(uc.getErrorStream()) tell me what went wrong. (uc =
(HttpURLConnection) url.openConnection();).

I will now try to move on to httpclient.

-Ajay


On Wed, Jan 13, 2010 at 11:53 PM, Oleg Kalnichevski <olegk@apache.org>wrote:

> Ajay Bansal wrote:
>
>> 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:ajay.bansal02@gmail.com] 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?
>>
>>
>
> http://hc.apache.org/httpcomponents-client/tutorial/html/fundamentals.html#d4e152
>
> Oleg
>
>  Regards
>> Ajay
>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
>> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>
>


-- 

Regards,

Ajay Bansal
Expert HRM Professionals
Telfax: +91 22 40033147, Mob: +91 9029002425
ajay@ehrmp.com, www.ehrmp.com
LinkedIn Profile : http://www.linkedin.com/in/abansal

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message