我目前正在組織一些數據並向我的本地Web服務器(Apache 2.4.27)發出POST請求。爲什麼在發送和接收HTTP 100繼續代碼後cURL掛起,而不是繼續執行正文?
這裏是我如何放在一起的要求:
public function sendPost($url, array $data) {
$ch = curl_init($url);
$httpCodes = parse_ini_file(CONF::HTTP_CODES_INI);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT , 30);
curl_setopt($ch, CURLOPT_TIMEOUT , 30);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, ['data' => json_encode($data)]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_VERBOSE, true);
//Ignore SSL issues, testing on a dev box
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($ch);
$curlInfo = curl_getinfo($ch);
$httpCode = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
$curlInfo["http_code"] = $httpCode . ': ' . $httpCodes[$httpCode];
if ($result === false || $httpCode > 299) {
$result = json_encode($curlInfo);
}
curl_close($ch);
return $result;
}
這是我從捲曲
* Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to my.local.server.com (127.0.0.1) port 80 (#0)
> POST /path/script.php?action=receive HTTP/1.1
Host: my.local.server.com
Accept: */*
Content-Length: 2645588
Expect: 100-continue
Content-Type: multipart/form-data; boundary=------------------------051580b0f5143de8
< HTTP/1.1 100 Continue
* Operation timed out after 30000 milliseconds with 0 bytes received
* Curl_http_done: called premature == 1
* Closing connection 0
但是看到對話內容,在調試時服務器上的腳本,我的確得到數據和請求似乎一直貫穿始終。根據我對HTTP 100 Continue
狀態碼的理解,cURL應該首先發送標題,請參閱continue
響應,然後發送數據。
您可以在上面看到,客戶端收到HTTP/1.1 100 Continue
,但隨後超時。
我試着將超時時間設置爲5分鐘,它仍然掛起,直到超時。
任何想法?
編輯:I'ved試圖用
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:'));
,試圖迫使continue
期望,不能設置。迴應是一樣的,只是沒有Expect: ...
部分。
它說「0字節** **收到**」,這可能是關鍵。它可能已經發送了所有字節,但它沒有收到任何東西......(好吧,在「100繼續」之後) –