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 <[email protected]<mailto:[email protected]>> Reply-To: HttpClient Discussion <[email protected]<mailto:[email protected]>> Date: Monday, April 6, 2015 at 3:44 AM To: HttpClient Discussion <[email protected]<mailto:[email protected]>> 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
