title: Guzzlehttp - How get the body of a response from Guzzle 6?
body: <p>I'm trying to write a wrapper around an api my company is developing.  It's restful, and using Postman I can send a post request to an endpoint like <code>http://subdomain.dev.myapi.com/api/v1/auth/</code> with a username and password as POST data and I am given back a token.  All works as expected.  Now, when I try and do the same from PHP I get back a <code>GuzzleHttp\Psr7\Response</code> object, but can't seem to find the token anywhere inside it as I did with the Postman request.  </p>
  
  <p>The relevant code looks like: </p>
  
  <pre><code>$client = new Client(['base_uri' =&gt; 'http://companysub.dev.myapi.com/']);
  $response = $client-&gt;post('api/v1/auth/', [
      'form_params' =&gt; [
          'username' =&gt; $user,
          'password' =&gt; $password
      ]
  ]);
  
  var_dump($response); //or $resonse-&gt;getBody(), etc...
  </code></pre>
  
  <p>The output of the code above looks something like (warning, incoming wall of text):</p>
  
  <pre><code>object(guzzlehttp\psr7\response)#36 (6) {
    ["reasonphrase":"guzzlehttp\psr7\response":private]=&gt;
    string(2) "ok"
    ["statuscode":"guzzlehttp\psr7\response":private]=&gt;
    int(200)
    ["headers":"guzzlehttp\psr7\response":private]=&gt;
    array(9) {
      ["connection"]=&gt;
      array(1) {
        [0]=&gt;
        string(10) "keep-alive"
      }
      ["server"]=&gt;
      array(1) {
        [0]=&gt;
        string(15) "gunicorn/19.3.0"
      }
      ["date"]=&gt;
      array(1) {
        [0]=&gt;
        string(29) "sat, 30 may 2015 17:22:41 gmt"
      }
      ["transfer-encoding"]=&gt;
      array(1) {
        [0]=&gt;
        string(7) "chunked"
      }
      ["content-type"]=&gt;
      array(1) {
        [0]=&gt;
        string(16) "application/json"
      }
      ["allow"]=&gt;
      array(1) {
        [0]=&gt;
        string(13) "post, options"
      }
      ["x-frame-options"]=&gt;
      array(1) {
        [0]=&gt;
        string(10) "sameorigin"
      }
      ["vary"]=&gt;
      array(1) {
        [0]=&gt;
        string(12) "cookie, host"
      }
      ["via"]=&gt;
      array(1) {
        [0]=&gt;
        string(9) "1.1 vegur"
      }
    }
    ["headerlines":"guzzlehttp\psr7\response":private]=&gt;
    array(9) {
      ["connection"]=&gt;
      array(1) {
        [0]=&gt;
        string(10) "keep-alive"
      }
      ["server"]=&gt;
      array(1) {
        [0]=&gt;
        string(15) "gunicorn/19.3.0"
      }
      ["date"]=&gt;
      array(1) {
        [0]=&gt;
        string(29) "sat, 30 may 2015 17:22:41 gmt"
      }
      ["transfer-encoding"]=&gt;
      array(1) {
        [0]=&gt;
        string(7) "chunked"
      }
      ["content-type"]=&gt;
      array(1) {
        [0]=&gt;
        string(16) "application/json"
      }
      ["allow"]=&gt;
      array(1) {
        [0]=&gt;
        string(13) "post, options"
      }
      ["x-frame-options"]=&gt;
      array(1) {
        [0]=&gt;
        string(10) "sameorigin"
      }
      ["vary"]=&gt;
      array(1) {
        [0]=&gt;
        string(12) "cookie, host"
      }
      ["via"]=&gt;
      array(1) {
        [0]=&gt;
        string(9) "1.1 vegur"
      }
    }
    ["protocol":"guzzlehttp\psr7\response":private]=&gt;
    string(3) "1.1"
    ["stream":"guzzlehttp\psr7\response":private]=&gt;
    object(guzzlehttp\psr7\stream)#27 (7) {
      ["stream":"guzzlehttp\psr7\stream":private]=&gt;
      resource(40) of type (stream)
      ["size":"guzzlehttp\psr7\stream":private]=&gt;
      null
      ["seekable":"guzzlehttp\psr7\stream":private]=&gt;
      bool(true)
      ["readable":"guzzlehttp\psr7\stream":private]=&gt;
      bool(true)
      ["writable":"guzzlehttp\psr7\stream":private]=&gt;
      bool(true)
      ["uri":"guzzlehttp\psr7\stream":private]=&gt;
      string(10) "php://temp"
      ["custommetadata":"guzzlehttp\psr7\stream":private]=&gt;
      array(0) {
      }
    }
  }
  </code></pre>
  
  <p>The output from Postman was something like:</p>
  
  <pre><code>{
      "data" : {
          "token" "fasdfasf-asfasdfasdf-sfasfasf"
      }
  }
  </code></pre>
  
  <p>Clearly I'm missing something about working with the response objects in Guzzle.  The Guzzle response indicates a 200 status code on the request, so I'm not sure exactly what I need to do to retrieve the returned data.</p>