title: PHP CURL: HTTP/1.1 411 Length Required
body: <p>Even I have specified the Content Length, I still receive the error:</p>
  
  <blockquote>
    <p><h2>Length Required</h2>
    <hr><p>HTTP Error 411. The request must be chunked or have a content length.</p></p>
  </blockquote>
  
  <p>This is my code</p>
  
  <pre><code>$curl = curl_init();
  $data = array("Key" =&gt; "Value", "Key2" =&gt; "Value2");
  $data = json_encode($data);
  $length = strlen($data);
  
  curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT");
  curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
  curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_NTLM);
  curl_setopt($curl, CURLOPT_USERPWD, "username:password");
  curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type: application/json;charset=utf-8", "Content-Length: $length"));
  curl_setopt($curl, CURLOPT_URL, $url);
  curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($curl, CURLOPT_FAILONERROR, false);
  curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
  curl_setopt($curl, CURLOPT_HEADER, true);
  
  $result = curl_exec($curl);
  </code></pre>
  
  <p>Any ideas whats wrong?</p>