hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Pete Keyes <PKe...@starbucks.com>
Subject Re: Not able to print response object while using async httpclient
Date Mon, 06 Apr 2015 14:53:05 GMT
Remove the line:
EntityUtils.consume(responseEntity);

That line completely consumes and discards the response body.

—
Pete Keyes
Starbucks Coffee Co.
w: 206-318-5933
c: 206-914-4134


From: Bhuvan Gupta <bhuvangu@gmail.com<mailto:bhuvangu@gmail.com>>
Reply-To: HttpClient Discussion <httpclient-users@hc.apache.org<mailto:httpclient-users@hc.apache.org>>
Date: Monday, April 6, 2015 at 3:44 AM
To: HttpClient Discussion <httpclient-users@hc.apache.org<mailto:httpclient-users@hc.apache.org>>
Subject: Not able to print response object while using async httpclient

Hello,

I am trying to do a httpGet request to google and print the response using async HttpClient,
But response always comes as the empty string.

A fragment of the code (complete project in attachment)

       CloseableHttpAsyncClient httpClient = HttpAsyncClients.createDefault();
        httpClient.start();
        HttpGet get = new HttpGet("http://google.com");
        httpClient.execute(get, new FutureCallback<HttpResponse>() {
            public void completed(final HttpResponse response) {
                try {
                    HttpEntity responseEntity = response.getEntity();
                    EntityUtils.consume(responseEntity);
                    StatusLine statusLine = response.getStatusLine();
                    System.out.println("statusLine::"  + statusLine);
                    String reponseBody = EntityUtils.toString(responseEntity);
                    System.out.println("reponseBody::" + reponseBody);
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }

In this code i am getting the ouput to be:
statusLine:: some status code like 200
responseBody:: empty string.

What am i doing wrong ?
I have tested with POST request as well, but same result


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