Android HttpResponse content(body) to String
- Home
- chevron_right
- Snippets
- chevron_right
- Android HttpResponse content(body) to String
Usually I use the following code to convert a Http response content to String:
BufferedReader in = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); StringBuilder responseBuilder = new StringBuilder(); String line = ""; while ((line = in.readLine()) != null) { responseBuilder.append(line); } in.close(); Log.e("WS RESPONSE", responseBuilder.toString());
It is not a bad idea but I found over the internet that there is a more elegant solution to do this and it is the following:
String responseString = EntityUtils.toString(response.getEntity()); Log.e("WS RESPONSE", responseString);