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:

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


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();
        HttpGet get = new HttpGet("http://google.com");
        httpClient.execute(get, new FutureCallback<HttpResponse>() {
            public void completed(final HttpResponse response) {
                try {
                    HttpEntity responseEntity = response.getEntity();
                    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

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
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message