我正在尝试使用带有 php curl 的 Web 服务,但我收到 http 代码“100”和“Recv 失败:连接已重置”错误。我使用 google chrome 的扩展名“Postman -REST Client”测试了 Web 服务"而且效果很好。我搜索了这个 http 代码,看起来服务器正在等待正文请求数据,但我不知道它希望我发送什么,因为我没有发布任何数据,只是标题。
我的代码如下所示:
error_reporting(-1);
$header = array('Content-Length: 1831', 'Content-Type: application/json', 'Authorization: '. $authorization, 'Authorization-Admin: '. $authorization_admin);
$url = 'http://api.bookingreports.com/public/1/analytics/reports/departures';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
$result = curl_exec($ch);
$errorCode = curl_getinfo($ch, CURLINFO_HEADER_OUT);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
echo $result;
echo curl_error($ch);
echo $errorCode;
echo $httpcode;
//log_message('debug', 'HTTP HEADER '. $errorCode);
curl_close($ch);
我发送的标题如下所示:
POST /public/1/analytics/reports/departures HTTP/1.1
Host: api.bookingreports.com
Accept: */*
Content-Length: 1831
Content-Type: application/json
Authorization: myauthcode
Authorization-Admin: myauthadmin
Expect: 100-continue