title: How to get response body in Guzzle
body: <p>How to get response when I post request with Guzzle I use <code>"guzzle/guzzle": "^3.9",</code>
  I post fro some url request and I need response body, but with Guzzle I dont find this is response, where use standard php function <code>file_get_contents</code> I have response body. How in Guzzle het response body ?</p>
  
  <pre><code>$guzzle = new Client();
  $postCell = $guzzle
      -&gt;post($url, [], $addProtectedRangeJson)
      -&gt;addHeader('Authorization', 'Bearer ' . $arrayAccessTokenClient)
      -&gt;addHeader('Content-type', 'application/json')
  ;
  
  $postCell
      -&gt;send()
      -&gt;getBody(true)
  ;
  
  $contents = (string) $postCell-&gt;getBody(); // get body that I post -&gt; my request, not response
  $contents = $postCell-&gt;getBody()-&gt;getContents(); // not find getContents, ask me did you mean to call getContentMd5 
  $answer = json_decode($postCell-&gt;getResponse()-&gt;getBody(), true);
  
  return $answer;
  </code></pre>
  
  <p>Now <code>$answer</code>:</p>
  
  <pre><code>result = {Guzzle\Http\EntityBody} [7]
  readWriteHash = {array} [2]
  contentEncoding = false
  rewindFunction = null
  stream = {resource} resource id='77' type='stream'
  size = null
  cache = {array} [9]
   wrapper_type = "PHP"
   stream_type = "TEMP"
   mode = "w+b"
   unread_bytes = 0
   seekable = true
   uri = "php://temp"
   is_local = true
   is_readable = true
   is_writable = true
  customData = {array} [1]
   default = true
  </code></pre>
  
  <p>I try <code>$contents = (string) $postCell-&gt;getBody();</code> but have my request, not response, but I need response</p>
  
  <pre><code>        $url = 'some_url';
      $opts = array('http' =&gt;
          array(
              'method'  =&gt; 'POST',
              'header'=&gt;"Content-type: application/json\r\n" .
                  "Authorization: Bearer $arrayAccessTokenClient\r\n",
              'content' =&gt; $addProtectedRangeJson
          )
      );
      // Creating the context for the request
      $context = stream_context_create($opts);
      $response = file_get_contents($url, FALSE, $context);
      $responseData = json_decode($response, TRUE);
  </code></pre>
  
  <p>How to get response body in Guzzle ?? </p>
  
  <p>I try http guzzle</p>
  
  <pre><code>$headers = [
          'Authorization' =&gt; 'Bearer ' . $arrayAccessTokenClient,
          'Content-type' =&gt; 'application/json'
      ];
      $guzzle = new \GuzzleHttp\Client($headers);
  
      $request = $guzzle
          -&gt;post('https://sheets.googleapis.com/v4/spreadsheets/' . $spreadsheetId . ':batchUpdate',
              $addProtectedRange
          );
      $response = $request-&gt;getBody()-&gt;getContents();
  
      return $response;
  </code></pre>
  
  <p>But have 401? hot to add header ? </p>
  
  <p><strong>UPDATE</strong></p>
  
  <pre><code>    $headers = [
          'Authorization' =&gt; 'Bearer ' . $arrayAccessTokenClient,
          'Content-type' =&gt; 'application/json'
      ];
      $guzzle = new \GuzzleHttp\Client();
      $request = new Request('POST', 'https://sheets.googleapis.com/v4/spreadsheets/' . $spreadsheetId . ':batchUpdate', $headers);
      $response = $guzzle
          -&gt;send($request, $addProtectedRange);
  
      $answer = $response-&gt;getBody()-&gt;getContents();
  
      return $answer;
  </code></pre>
  
  <p>but have</p>
  
  <pre><code>  "Catchable Fatal Error: Argument 1 passed to GuzzleHttp\\Client::send() must be an instance of Psr\\Http\\Message\\RequestInterface, instance of Guzzle\\Http\\Message\\Request given, called in /home/ivan/host/aog-code/src/Artel/SiteBundle/Helper/GoogleSpreadSheetHelper.php on line 144 and defined"
  </code></pre>