title: Laravel 5.1 Guzzle - Undefined offset: 0
body: <p>I need to access an API so I use guzzle6 and I write a function:</p>
  
  <pre><code>public function test()
      {
  
  $client = new GuzzleHttp\Client(['defaults' =&gt; ['verify' =&gt; false]]);
  
  try {
  $res = $client-&gt;post('https://example.com/api/v2/oauth/token?grant_type=client_credentials', [
      'headers' =&gt; [
          'Content-Type' =&gt; 'application/x-www-form-urlencoded',
      ],
  
      'auth' =&gt; [
          'Username' =&gt; 'user_5639',
          'Password' =&gt; 'pass_asdhbas67yausihd7qaw8'
  ]
              ]);
  
  $res = json_decode($res-&gt;getBody()-&gt;getContents(), true);
  }
  
  catch (GuzzleHttp\Exception\ClientException $e) {
          $response = $e-&gt;getResponse();
          $result =  json_decode($response-&gt;getBody()-&gt;getContents());
  
      return response()-&gt;json(['data' =&gt; $result]);
  }
  
      }
  </code></pre>
  
  <p>but I got error:</p>
  
  <blockquote>
    <p>ErrorException in Client.php line 346: Undefined offset: 0</p>
  </blockquote>
  
  <p>When I try at POSTMAN the same request everything is fine:
  <a href="https://i.stack.imgur.com/ODL1R.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ODL1R.png" alt="enter image description here"></a></p>
  
  <p>How to solve my problem?</p>