title: Sending a POST with PHP doesn't work with curl or file_get_contents, just normal bash CURL
body: <p>I'm having some serious problems sending a POST. Using curl on the shell, my POST works perfectly. However, when using PHP curl, or file_get_contents, it doesn't work at all. I get a 500 error from the webserver.</p>
  
  <pre><code>curl -X POST -H"Content-Type:application/xml" "http://myserver:8080/createItem?name=NewItem" --user root:123456 --data-binary @template.xml
  </code></pre>
  
  <p>And this:</p>
  
  <pre><code>$options = array(
      CURLOPT_HEADER =&gt; 1, 
      CURLOPT_HTTPHEADER =&gt; array("Content-Type:application/xml"),
      CURLOPT_URL =&gt; "http://myserver:8080/createItem?name=" . rawurlencode("NewItem"), 
      CURLOPT_FRESH_CONNECT =&gt; 1, 
      CURLOPT_RETURNTRANSFER =&gt; 1, 
      CURLOPT_FORBID_REUSE =&gt; 1, 
      CURLOPT_TIMEOUT =&gt; 20, 
      CURLOPT_HTTPAUTH =&gt; CURLAUTH_BASIC,
      CURLOPT_USERPWD =&gt; "root:123456",
      CURLOPT_POST =&gt; 1,
      CURLOPT_POSTFIELDS =&gt; file_get_contents("template.xml"),
  );
  
  $post = curl_init(); 
  curl_setopt_array($post, $options); 
  if(!$result = curl_exec($post)) { 
      trigger_error(curl_error($post)); 
  } 
  
  curl_close($post); 
  </code></pre>
  
  <p>And this:</p>
  
  <pre><code>$context = stream_context_create(array(
      'http' =&gt; array(
          'method'  =&gt; 'POST',
          'header'  =&gt; sprintf("Authorization: Basic %s\r\n", base64_encode('root:123456')) . "Content-Type:application/xml",
          'timeout' =&gt; 20,
          'content' =&gt; file_get_contents("template.xml"),
      ),
  ));
  $ret = file_get_contents("http://myserver:8080/createItem?name=" . rawurlencode("NewItem"), false, $context);
  </code></pre>
  
  <p>Am i doing something absurd here and i'm not seeing? I don't see a reason for the normal curl from the shell to work perfectly, but not the PHP implementations. </p>