OAuth,PHP,Rest API和curl提供400 Bad Request

我们使用了带有OAuth 1.0的car2go Rest-API ,获得了几个应用程序。

我们所有的网络应用程序在2天前停止工作。 所有curl POST请求现在都失败,出现以下错误:

 400 Bad Request Your browser sent a request that this server could not understand. Error code: 53 Parser Error: [Content-Length: -] 

我花了很多时间试图找出问题是否是我的oauth工作流程。 但最终所有参数和签名和内容都是正确的。 我通过Postman成功启动了POST (REST-Client)

所以我的结论是,不知何故,curl的PHP代码突然不再起作用了。

这是(非常难看的)curlfunction。 关于curl POST的大多数教程的不同之处在于,我传递的是一个已经附加了所有参数的完整URL,所以我不需要CURLOPT_POSTFIELDS

 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); } 

好的,这是解决这个噩梦的原因:

 curl_setopt($ch,CURLOPT_HTTPHEADER ,array('Content-Length: 0')); 

很明显,没有标题发送curlPOST是不行的。