private static void printDebugInfo(HttpUriRequest request, HttpResponse response) { String br = System.getProperty("line.separator"); StringBuffer builder = new StringBuffer(); builder.append("URL: "); builder.append(request.getURI().toString()); builder.append(br); builder.append("Request Headers: "); builder.append(headersToString(request.getAllHeaders())); builder.append(br); builder.append("Request Body: "); if (request instanceof HttpPost) { HttpPost post = (HttpPost) request; String body = "This body can't be outputted."; try { body = ResponseUtil.fromHttpEntityToString(post.getEntity(), "UTF-8"); } catch (ResponseBodyParseException e) { Log.d(TAG, "Parsing request is failed.", e); } builder.append(body); } else { builder.append("No body by Get request."); } builder.append(br); builder.append("HTTP Status Code: "); builder.append(response.getStatusLine().getStatusCode()); builder.append(br); builder.append("Response Headers: "); builder.append(headersToString(response.getAllHeaders())); builder.append(br); Header contentType = response.getFirstHeader("Content-Type"); if (contentType != null && "application/json".equals(contentType.getValue())) { builder.append("Response Body: "); String body = "This body can't be outputted."; try { body = ResponseUtil.fromHttpEntityToString(response.getEntity(), "UTF-8"); response.setEntity(new StringEntity(body, "UTF-8")); } catch (ResponseBodyParseException e) { Log.d(TAG, "Parsing response is failed.", e); } catch (UnsupportedEncodingException e) { Log.e(TAG, e.getMessage()); } builder.append(body); builder.append(br); } else { builder.append("Response Body is binary data."); builder.append(br); } Log.d(TAG, builder.toString()); }