php 接口400错误,OAuth,PHP,Rest API和curl发出400错误请求

我们使用了带有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工作流程上。但是最后所有参数,签名和内容都是正确的。我成功地POST通过via

邮递员(REST客户端)

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

这是(非常难看)卷曲功能。与大多数有关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);

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值