curl 错误(56):使用PHP从对等方接收REST API post方法请求的数据时失败

sycxhyv7  于 2022-11-13  发布在  PHP
关注(0)|答案(1)|浏览(134)

响应应该是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;
6kkfgxo0

6kkfgxo01#

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

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

添加这两个头后,它就可以正常工作了。在发送请求到服务器之前,请询问服务器端人员有关头和参数的信息

相关问题