title: PHP, curl, Unable to set custom header
body: <p>Somehow I cannot set custom headers for the PHP curl call. The following code is working on my server (x86_64-redhat-linux-gnu, curl version 7.40.0) but it does not work on the server of our customer (x86_64-pc-linux-gnu, curl version 7.43.0).</p>
  
  <pre><code>    $bodyString = json_encode($body);
      $options = array(
          CURLOPT_URL =&gt; $url,
          CURLOPT_HEADER =&gt; 0,
          CURLOPT_CUSTOMREQUEST =&gt; "POST",
          CURLOPT_RETURNTRANSFER =&gt; TRUE,
          CURLOPT_FOLLOWLOCATION =&gt; TRUE,
          CURLOPT_TIMEOUT =&gt; 10,
          CURLOPT_HTTPAUTH =&gt; CURLAUTH_BASIC,
          CURLOPT_USERPWD =&gt; "$customerId:$licenceKey",
          CURLOPT_SSL_VERIFYPEER =&gt; FALSE,
          CURLINFO_HEADER_OUT  =&gt; TRUE,
  
          CURLOPT_HTTPHEADER =&gt; array(
              'Content-Type: application/json',
              'Content-Length: ' . strlen($bodyString),
          ),
          CURLOPT_POSTFIELDS =&gt; $bodyString
      );
  
      log("Requesting [".$url."]...");
  
      $cURL = curl_init();
      curl_setopt_array($cURL, $options);
      $response = curl_exec($cURL);
  
      log("Header dump:\n ".curl_getinfo($cURL, CURLINFO_HEADER_OUT));
  </code></pre>
  
  <p>On our server it works as expected and CURLINFO_HEADER_OUT returns:</p>
  
  <pre><code>POST /api/rest_call?p1=true&amp;p2=true HTTP/1.1
  Authorization: Basic *****
  Host: admin.myserver.net
  Accept: */*
  Content-Type: application/json
  Content-Length: 119
  </code></pre>
  
  <p>On the customers server the CURLINFO_HEADER_OUT returns an empty string. The requested server returns "415 Unsupported media type" because no "Content-Type" was transferred.</p>
  
  <p><strong>UPDATE</strong>: Followed the hint from <a href="https://stackoverflow.com/questions/3757071/php-debugging-curl/14436877#14436877">Php - Debugging Curl</a> I created the verbose log file. Here is a part of it:</p>
  
  <pre><code>POST /api/rest_call?p1=true&amp;p2=true HTTP/1.1
  Host: admin.yoochoose.net
  Accept: */*
  </code></pre>
  
  <p>All the custom headers and(!) the authentication information seems to be ignored by cURL. Any ideas?</p>