getting the response body of HttpResponse

Solution 1:

First, see if your server is not returning blank response:

response.getEntity().getContentLength();  //it should not be 0

Second, try the following to convert response into string:

StringBuilder sb = new StringBuilder();
try {
    BufferedReader reader = 
           new BufferedReader(new InputStreamReader(entity.getContent()), 65728);
    String line = null;

    while ((line = reader.readLine()) != null) {
        sb.append(line);
    }
}
catch (IOException e) { e.printStackTrace(); }
catch (Exception e) { e.printStackTrace(); }


System.out.println("finalResult " + sb.toString());

Solution 2:

You can use this one:

String s = EntityUtils.toString(httpRes.getEntity());

Solution 3:

 org.apache.http.conn.BasicManagedEntity@f8a5dec

response come when we directly print HttpEntity object. eg:

 HttpEntity httpEntity=httpResponse.getEntity();

Now for getting the actual Response from the server we need to do following steps:

 public String convertStreamtoString(InputStream is){

    String line="";
    String data="";
    try{
        BufferedReader br=new BufferedReader(new InputStreamReader(is));
        while((line=br.readLine())!=null){

            data+=line;
        }
    }
    catch(Exception e){
        e.printStackTrace();
    }
        return  data;
}

just call above method and pass httpEntity as an argument. Enjoy!!

Solution 4:

Try this:

BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
String body = "";
while ((body = rd.readLine()) != null) 
{
    Log.e("HttpResponse", body);
}