你不能。
With curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl請按照響應LOCATION
僅限於3xx
狀態碼。
AFAIK並聲明作爲文件沒有辦法迫使捲曲跟隨201位迴應的位置。
您必須解析標頭,獲取LOCATION,然後發出第二個捲曲請求。
以下位置的狀態不同於3xx
將是一個異常。此外,從curl命令行工具和C庫documentation:-L, --location -- (HTTP) If the server reports that the requested page has moved to a different location (indicated with a Location: header and a 3XX response code), this option will make curl redo the request on the new place
給人一種快看捲曲源代碼,你會發現在/lib/http.c
功能Curl_http_readwrite_headers
。
位置遵循的是裏面有這個條件處理:
else if((k->httpcode >= 300 && k->httpcode < 400) &&
checkprefix("Location:", k->p) &&
!data->req.location) {
/* this is the URL that the server advises us to use instead */
char *location = Curl_copy_header_value(k->p);
if(!location)
return CURLE_OUT_OF_MEMORY;
if(!*location)
/* ignore empty data */
free(location);
else {
data->req.location = location;
if(data->set.http_follow_location) {
DEBUGASSERT(!data->req.newurl);
data->req.newurl = strdup(data->req.location); /* clone */
if(!data->req.newurl)
return CURLE_OUT_OF_MEMORY;
/* some cases of POST and PUT etc needs to rewind the data
stream at this point */
result = http_perhapsrewind(conn);
if(result)
return result;
}
}
}
位置之後與300
和399
謝謝,我開始懷疑這一點。你能添加一個鏈接到描述這個的文檔嗎?我認爲這會改善答案,我很樂意接受它。 – billynoah
http://php.net/manual/en/function.curl-setopt.php – Paolo
我刪除了評論,還發布了一部分源代碼,它提供了對文檔的解釋是正確的線索(狀態沒有重定向超出範圍3xx) – Paolo