title: How to get HttpClient returning status code and response body?
body: <p>I am trying to get Apache HttpClient to fire an HTTP request, and then display the HTTP response code (200, 404, 500, etc.) as well as the HTTP response body (text string). It is important to note that I am using <code>v4.2.2</code> because most HttpClient examples out there are from <code>v.3.x.x</code> and the API changed greatly from version 3 to version 4.</p>
  
  <p>Unfortunately I've only been able to get HttpClient returning the status code <strong>or</strong> the response body (but not both).</p>
  
  <p>Here's what I have:</p>
  
  <pre><code>// Getting the status code.
  HttpClient client = new DefaultHttpClient();
  HttpGet httpGet = new HttpGet("http://whatever.blah.com");
  HttpResponse resp = client.execute(httpGet);
  
  int statusCode = resp.getStatusLine().getStatusCode();
  
  
  // Getting the response body.
  HttpClient client = new DefaultHttpClient();
  HttpGet httpGet = new HttpGet("http://whatever.blah.com");
  ResponseHandler&lt;String&gt; handler = new BasicResponseHandler();
  
  String body = client.execute(httpGet, handler);
  </code></pre>
  
  <p>So I ask: <strong>Using the <code>v4.2.2</code> library, how can I obtain both status code and response body from the same <code>client.execute(...)</code> call?</strong> Thanks in advance!</p>