8
PHP cURL HTTP代码返回0
我不明白当我回显$ httpCode时,我总是得到0,当我将$ html_brand更改为残破的url时,我期望是404。有什么我想念或不知道的吗?谢谢。 //check if url exist $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $html_brand); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); $response = curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); if ($httpCode == 404) { echo "The Web Page Cannot Be Found"; return; } curl_close($ch);