【问题标题】:Error (56): Failure when receiving data from the peer for rest API post method request using PHP错误 (56):使用 PHP 从对等方接收数据以获取 REST API 发布方法请求时失败
【发布时间】:2017-04-28 08:16:31
【问题描述】:

响应应该是 XML,但我在使用标头向 REST API 发送请求时收到类似 (56): Failure when receiving data from the peer 的错误,这是根据客户端的示例请求

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...”、“Host”、“Content-Length”,让 curl 自己制作。然后您可能还想提交一些实际数据(我想是 52 个字节)。
  • @DanielStenberg:你能举个例子吗
  • @DanielStenberg: 现在我收到错误 #:Recv failure: Connection was reset
  • 如果您更改了代码/错误,那么我建议您更新问题,否则将无法理解我们现在的位置。 “连接已重置”发生在 curl 几乎无法影响的连接级别上,因此存在根本性的问题。例如,也许您应该使用 HTTPS?

标签: php rest api curl token


【解决方案1】:

我未能在 POST 请求中发送这两个标头

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

添加这两个标题后,它工作正常。在将您的请求发送到服务器之前,请向服务器端人员询问标头和参数

【讨论】:

    猜你喜欢
    • 2014-06-20
    • 2015-03-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多