title: How to add headers in Guzzle http
body: <p>I'm building a small application in <code>Laravel 5.5</code> where I'm using <code>Guzzle Http</code> to get call the api url and get the response, Few of the api calls have certain condition to have headers which works as authorization of the request generated. I'm trying to place the header something like this:</p>
  <pre><code>public function post(Request $request)
  {
      try {
          if ($request-&gt;url_method == 'get') {
              $request = $this-&gt;client-&gt;get($request-&gt;url, [ 'headers' =&gt; [ 'access_token' =&gt; $request-&gt;headers-&gt;access_token]]);
          }
          else if ($request-&gt;url_method == 'post')
          {  $request = $this-&gt;client-&gt;post($request-&gt;url, [$request-&gt;request_data]);  }
          else { return response()-&gt;json(['data' =&gt; 'Invalid Method'],500);   }
  
          $response = \GuzzleHttp\json_decode($request-&gt;getBody());
          return response()-&gt;json(['data' =&gt; json_decode($response-&gt;d)], $request-&gt;getStatusCode());
      }
      catch (ClientException $e) {
          return response()-&gt;json(['data' =&gt; 'Invalid Request.'], $request-&gt;getStatusCode());
      }
  }
  </code></pre>
  <p>But this is giving me errors:</p>
  <blockquote>
  <p>Undefined property: Symfony\Component\HttpFoundation\HeaderBag::$access_token</p>
  </blockquote>
  <p>Please checkout the screenshot:</p>
  <p><a href="https://i.stack.imgur.com/o6Pum.png" rel="noreferrer"><img src="https://i.stack.imgur.com/o6Pum.png" alt="Guzzle HTTP client error" /></a></p>
  <p>Also when calling through the browser in console it gives me the same error:</p>
  <p><a href="https://i.stack.imgur.com/HDjKS.png" rel="noreferrer"><img src="https://i.stack.imgur.com/HDjKS.png" alt="Browser console error" /></a></p>
  <p>Help me out in this, Thanks.</p>