title: Is there a way to get the String value of an HttpEntity when EntityUtils.toString() returns an exception?
body: <p>I keep running into this situation where I get back a bad HTTP response (like a 400) but cannot look at the HttpEntity in the HttpResponse object.  When I step through with the debugger, I can see that the entity has content (length > 0) and I can even look at the content, but all I see is an array of numbers (ASCII codes I guess?) which isn't helpful.  I'll call EntityUtils.toString() on the entity, but I get back an exception -- either an IOException, or some kind of "object is in an invalid state" exception.  This is really frustrating!  Is there any way to get at this content in a human-readable form?</p>
  
  <p>Here is my code :</p>
  
  <pre><code>    protected JSONObject makeRequest(HttpRequestBase request) throws ClientProtocolException, IOException, JSONException, WebRequestBadStatusException {
  
      HttpClient httpclient = new DefaultHttpClient();
  
      try {
          request.addHeader("Content-Type", "application/json");
          request.addHeader("Authorization", "OAuth " + accessToken);
          request.addHeader("X-PrettyPrint", "1");
  
          HttpResponse response = httpclient.execute(request);
          int statusCode = response.getStatusLine().getStatusCode();
  
          if (statusCode &lt; 200 || statusCode &gt;= 300) {
              throw new WebRequestBadStatusException(statusCode);
          }
  
          HttpEntity entity = response.getEntity();
  
          if (entity != null) {
              return new JSONObject(EntityUtils.toString(entity));
          } else {
              return null;
          }
  
      } finally {
          httpclient.getConnectionManager().shutdown();
      }
  }
  </code></pre>
  
  <p>See where I throw the exception?  What I'd like to do is suck out the content of the HttpEntity and put it in the exception.</p>