【发布时间】: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?