Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HttpResponse to String android

Tags:

android

I am trying to covert the http response to string using the code below, but my response string is getting terminated in the middle any ideas, how to convert http response to string so that i dont get any buffer problem.

private static String convertStreamToString(InputStream is) {     BufferedReader reader = new BufferedReader(new InputStreamReader(is));     StringBuilder sb = new StringBuilder();     String line = null;     try {         while ((line = reader.readLine()) != null) {             sb.append((line + "\n"));         }     } catch (IOException e) {         e.printStackTrace();     } finally {         try {             is.close();          } catch (IOException e) {             e.printStackTrace();          }     }     return sb.toString(); } 

Anyone any suggestion please help. Thanks Deepesh

like image 418
Max Avatar asked Jul 28 '11 04:07

Max


People also ask

How do you get a response body from Clienthttpresponse?

To get the response body as a string we can use the EntityUtils. toString() method. This method read the content of an HttpEntity object content and return it as a string. The content will be converted using the character set from the entity object.

How do you read a response body in Golang?

To read the body of the response, we need to access its Body property first. We can access the Body property of a response using the ioutil. ReadAll() method. This method returns a body and an error.

What is HTTP Response in Java?

An HTTP response. An HttpResponse is not created directly, but rather returned as a result of sending an HttpRequest . An HttpResponse is made available when the response status code and headers have been received, and typically after the response body has also been completely received.


1 Answers

i think, there is a simpler way:

String result = EntityUtils.toString(resp_entity); 

right?

like image 56
Simon Avatar answered Oct 05 '22 23:10

Simon