title: Can't Set "Host:" Header with CURL Request
body: <p>I am trying to make a CURL request with some basic authentication (through sending an encrypted header). However, when I try to set the <code>"Host: _"</code> header, the remote server responds with:</p>
  
  <blockquote>
    <p>Bad Request: Your browser sent a request that this server could not understand.</p>
  </blockquote>
  
  <p>Here's the code that makes the CURL call. Note that it works as soon as I comment out the <code>"Host: url"</code> header in the <code>$http_header</code> variable. However, it is used on the target server as part of the authentication procedure, so I can not simply remove it.</p>
  
  <pre><code>    $curl = curl_init();
  
      $opt = array(
          CURLOPT_URL=&gt;$url,
          CURLOPT_RETURNTRANSFER=&gt;1,
          CURLOPT_HTTPHEADER=&gt;$http_header,
          CURLOPT_POST=&gt;1,
          CURLOPT_POSTFIELDS=&gt;$data_params,
          CURLOPT_CONNECTTIMEOUT=&gt;5, // Timeout to 5 seconds
      );
      curl_setopt_array($curl, $opt);
  
      // $output contains the output string
      $output = curl_exec($curl);
  
      // it closes the session
      curl_close($curl);
  </code></pre>
  
  <p>The contents of <code>$http_header</code> (an associative array):</p>
  
  <pre><code>array
    0 =&gt; string 'Host: http://localhost/work/myproject'
    1 =&gt; string 'Content-Type: multipart/form-data'
    2 =&gt; string 'X-Authorization: Basicauth Z2xZjA2YzJhMzIxYTI1ZmIzZTgxYQ=='
  </code></pre>