title: OAuth, PHP, Rest API and curl gives 400 Bad Request
body: <p>We got a couple of apps, utilizing the <a href="https://code.google.com/p/car2go/wiki/index_v2_1" rel="nofollow">car2go Rest-API</a> with OAuth 1.0.</p>
  
  <p>All our web apps stopped working 2 days ago. All <code>curl</code> <code>POST</code> requests are failing now with the following error:</p>
  
  <pre><code>400 Bad Request
  Your browser sent a request that this server could not understand.
  Error code: 53
  Parser Error: [Content-Length: -]
  </code></pre>
  
  <p>I spend a lot of time trying to figure out if the problem is my oauth workflow. But in the end all parameters and signatures and stuff is correct. I successfully fire the <code>POST</code> via <a href="https://chrome.google.com/webstore/detail/postman-rest-client/fdmmgilgnpjigdojojpjoooidkmcomcm" rel="nofollow">Postman</a> (REST-Client)</p>
  
  <p>So my conclusion is that somehow the php code for the curl is suddenly not working anymore.</p>
  
  <p>This is the (very ugly) curl function. A difference to most tutorials about curl POST is, that I'm passing a full URL with all parameters already attached, so I don't need <code>CURLOPT_POSTFIELDS</code>.</p>
  
  <pre><code>function curlAPI($params) {
  
      //open connection
      $ch = curl_init();
  
      $url = $params['url'];
  
  
      curl_setopt($ch,CURLOPT_HEADER,false);
  
      //set the url, number of POST vars, POST data
      curl_setopt($ch,CURLOPT_URL,$url);
  
  
      curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
      curl_setopt($ch, CURLOPT_FOLLOWLOCATION,true);
      curl_setopt($ch, CURLOPT_MAXREDIRS,50);
  
      curl_setopt($ch, CURLOPT_TIMEOUT_MS, 5000);
  
      if($params['type'] == 'POST') {
          // POST
          curl_setopt($ch,CURLOPT_POST, true);
      } else if($params['type'] == 'DELETE') {
          // DELETE
          curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
      } else if($params['type'] == 'PUT') {
          $update_json = array();
          // PUT
          curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
          curl_setopt($ch, CURLOPT_POSTFIELDS,'');
      } else {
          // GET
          curl_setopt($ch,CURLOPT_POST,0);
      }
  
  
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  
      curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  
      //execute post
      $result['result'] = curl_exec($ch);
  
      // debug
      if (FALSE === $result['result']) {
          $result['errorInfo'] = curl_error($ch).' - '.curl_errno($ch);
      }
  
      $reponseInfo = array();
  
      $reponseInfo['info'] = curl_getinfo($ch);
      $reponseInfo['error'] = curl_error($ch);
  
      //close connection
      curl_close($ch);
  
  
      $result['reponseInfo'] = $reponseInfo;
      return json_encode($result);
  
  }
  </code></pre>