php - 错误 (56) : Failure when receiving data from the peer for rest API post method request using PHP

标签 php rest api curl token

响应应该是 XML,但我收到类似 (56): Failure when receiving data from the peer 的错误,同时使用 header 将请求发送到 REST API,这是示例请求给客户

POST http://api.toyotautrust.in/1.0/olx/inventory HTTP/1.1
User-Agent: Fiddler
Authorization: Token ******-****-****-****-***********
Host: api.toyotautrust.in
Content-Length: 52

这是我使用 cURL 用 PHP 编写的请求代码

$headers1=[
'POST /1.0/olx/inventory HTTP/1.1',
        'Host: api.toyotautrust.in',
        'User-Agent: Fiddler',
        'Authorization: Token' .$atoken1,
        'Content-Length: 52'];
$ch1 = curl_init();
curl_setopt($ch1, CURLOPT_URL, 'http://api.toyotautrust.in/1.0/olx/inventory');
curl_setopt($ch1, CURLOPT_POST, true);
curl_setopt($ch1, CURLOPT_HEADER, true);
curl_setopt($ch1, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch1, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch1, CURLOPT_HTTPHEADER,$headers1);
$response1 = curl_exec($ch1);
print_r($response1);
$status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
echo $status_code1;

最佳答案

我在 POST 请求中发送这两个 header 失败了

'User-Agent:Fiddler',
"Content-length: 0",

添加这两个 header 后,一切正常。在将您的请求发送到服务器之前,请向服务器端人员询问 header 和参数

关于php - 错误 (56) : Failure when receiving data from the peer for rest API post method request using PHP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41118232/

相关文章:

php - PDO ORDER BY 不适用于非自动增量的字段

php - 加密文本以存储在 mysql 数据库中的最佳方法

api - 当我尝试创建存储库时,Github Api v3 给出 404

PHP重定向功能

php - iPhone 应用程序用户标识符

java - Rest API SSL 带有 ca 签名的证书

iphone - 如果我希望我的 iOS 应用程序使用返回 XML 数据的 RESTful WebService,我想开始学习哪些 API?

java - Rest WS 中的动态请求参数

java - 使用 Play Framework 在应用程序启动时实例化 Controller 中的变量

api - 带有 OLTP 和 OLAP 数据库的 CQRS 有意义吗?