我想在我的PHP應用程序中使用cURL。我去了enter link description here,並找到了它的文件。但是當我想要實現我的代碼時,我發現cURL並不總是在無效的URL上返回錯誤。
爲了確保它,我將this example中提到的URL更改爲http://www.googles123.com
,這是無效的和註冊的。爲什麼cURL不會在無效URL上返回錯誤?
<?php
// Create a curl handle to a non-existing location
$ch = curl_init('http://www.googles123.com/');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
if(curl_exec($ch) === false)
{
echo 'Curl error: ' . curl_error($ch);
}
else
{
echo 'Operation completed without any errors';
}
// Close handle
curl_close($ch);
?>
的結果操作完成,沒有任何錯誤!儘管此代碼在其默認URL http://404.php.net/
上返回了錯誤。爲什麼?
你必須curl_getinfo($ CH)的使用和查看HTML的ERROR_CODE。所有錯誤都在curl_errno($ ch)中。 – SoftGuide