title: How to make a HTTP POSTrequest to an API using headers
body: <p>I need to integrate an API into my app.
  The docs say:</p>
  
  <p><strong>HTTP POST
      The following is a sample HTTP POST request and response. The placeholders shown need to be replaced with actual values.</strong></p>
  
  <pre><code>POST /partnerhubwebservice.asmx/Authorise HTTP/1.1
  Host: stage.example.co.uk
  Content-Type: application/x-www-form-urlencoded
  Content-Length: length
  
  username=string&amp;password=string
  </code></pre>
  
  <p>and response is:</p>
  
  <pre><code>HTTP/1.1 200 OK
  Content-Type: text/xml; charset=utf-8
  Content-Length: length
  
  &lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;AuthorisationResult xmlns="http://webservice.example.co.uk/"&gt;
    &lt;Token&gt;string&lt;/Token&gt;
  &lt;/AuthorisationResult&gt;
  </code></pre>
  
  <p>Reading the docs I create this function in Laravel Controller:</p>
  
  <pre><code>public function testRld() {
  
      $client = new GuzzleHttp\Client();
  try {
      $res = $client-&gt;post('http://stage.example.co.uk/partnerhubwebservice.asmx/Authorise', [
      'headers' =&gt; [
          'Content-Type' =&gt; 'application/x-www-form-urlencoded',
              ],
      'x-www-form-urlencoded' =&gt; [
          'Username' =&gt; 'MMM_bookings',
          'Password' =&gt; 'passwordaaaa',
  ]
              ]);
  
  return $res;
  
  }
  
  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 a message:</p>
  
  <blockquote>
    <p>ServerException in RequestException.php line 111: Server error: <code>POST
    http://stage.example.co.uk/partnerhubwebservice.asmx/Authorise</code>
    resulted in a <code>500 Internal Server Error</code> response: Missing parameter:
    username.</p>
  </blockquote>
  
  <p>When I try this at POSTMAN app everything is fine and there I get response ike:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;AuthorisationResult xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://webservice.example.co.uk/"&gt;
      &lt;RequestSuccessful&gt;true&lt;/RequestSuccessful&gt;
      &lt;ErrorMessage /&gt;
      &lt;Token&gt;27d67d31-999-44e0-9851-d6f427fd2181&lt;/Token&gt;
  &lt;/AuthorisationResult&gt;
  </code></pre>
  
  <p>Please help me to solve this problem? What is wrong with my code? WHy I got the error , and POSTMAN request works fine ...</p>