Max Max - 5 months ago 8
Android Question

HttpResponse to String 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

Answer

i think, there is a simpler way:

String result = EntityUtils.toString(resp_entity);

right?

Comments