title: cURL 'Content-length required' error... 3 days of searching, no luck
body: <p>Before you ask: I have already checked every similar question that already had an answer, and none of the proposed solutions work. So I'm hoping someone may be able to notice a mistake in my code. </p>
  
  <p>When submitting a cURL post to Google, I am returned with a 411 error, "POST requests require a Content-length header"</p>
  
  <pre><code>//Info required to authenticate
  $URL = "https://www.google.com/accounts/ClientLogin";
  $POST = http_build_query(array(
   'Email' =&gt; 'XXXXXXX@gmail.com',
   'Passwd' =&gt; 'XXXXXXXXXXXXXXX',
   'source' =&gt; 'primary',
   'service' =&gt; 'cl'
  ));
  
  $ch = curl_init( $URL );
  curl_setopt($ch, CURLOPT_POST, 1);
  curl_setopt($ch, CURLOPT_POSTFIELDS, $POST);
  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  curl_setopt($ch, CURLOPT_HEADER, 1); 
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
  $response = curl_exec($ch); //returns SID=&lt;sid code&gt;nLSID=&lt;lsid code&gt;nAuth=&lt;auth code&gt; or ERROR=&lt;message&gt;
  if ( curl_errno($ch) )
   die( 'Error contacting server' );
  
  //Successful auth results in http code 200
  if ( curl_getinfo($ch, CURLINFO_HTTP_CODE) != 200 )
   die( 'Failed to authenticate' );
  
  //Extract auth code - Authorization: GoogleLogin auth=yourAuthToken
  $auth_code = substr($response, strpos($response, 'Auth=')+5);
  
  //We're done here
  curl_close($ch);
  
  
  $url = "https://www.googleapis.com/calendar/v3/calendars/".urlencode('XXXXXXXXXXXXX@developer.gserviceaccount.com')."/events?sendNotifications=true&amp;pp=1&amp;key=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXx";  
  
  $post_data = http_build_query(array(
      "end" =&gt; array("dateTime" =&gt; "2013-14-11T10:40:00.000-07:00"),  
      "start" =&gt; array("dateTime" =&gt; "2013-14-11T10:00:00.000-07:00"),  
      "summary" =&gt; "my_summary",
      "description" =&gt; "my_description"
  ));
  
  $headers = array(
      'Authorization: GoogleLogin auth='.$auth_code.'',
      'Content-Type: application/json'
  );
  
  $ch2 = curl_init();  
  curl_setopt($ch2, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_POST, true);
  curl_setopt($ch2, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch2, CURLOPT_HTTPHEADER, $headers);
  curl_setopt($ch2, CURLOPT_POSTFIELDS, $post_data);  
  
  $output = curl_exec($ch2);  
  
  curl_close($ch2);
  
  echo '&lt;pre&gt;'.print_r($output).'&lt;/pre&gt;';
  </code></pre>
  
  <p>Things I have tried:</p>
  
  <p>-Adding the 'Content-length: '.strlen($post_data)</p>
  
  <p>-Content-type of 'x-www-form-urlencoded'</p>
  
  <p>-using a very simply json string for post_data so that I didn't use http_build_query</p>
  
  <p>-Trying to make it send as a PUT instead of POST</p>
  
  <p>-And a few other things over the course of the last few days that I can't quite recall right now</p>
  
  <p>Intent: To add an event to only MY calendar using only PHP with no authentication steps required by the user. This must be able to run all within a php function, asynchronously (called via AJAX)</p>
  
  <p>NOTE: Not using Wordpress or any other CMS</p>
  
  <p>-Kyle</p>