我有这个 cUrl 请求有时有效,然后停止工作。我正在回显标题和任何错误,http 显示 200 ok 并且没有错误,但内容长度为 0。
$userAgent = 'Googlebot/2.1 (http://www.googlebot.com/bot.html)';
$cslbnum = "881126";
$target_url = "https://www2.somewebsite.aspx?LicNum=" . $cslbnum;
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
curl_setopt($ch, CURLOPT_REFERER, "https://www2.somesite.aspx");
curl_setopt($ch, CURLOPT_URL,$target_url);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_TIMEOUT, 100);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
if(curl_exec($ch) === false)
{
echo 'Curl error: ' . curl_error($ch);
}
else
{
echo 'Operation completed without any errors';
}
$html = curl_exec($ch);
$html = @mb_convert_encoding($html, 'HTML-ENTITIES', 'utf-8');
curl_close( $ch );
echo $html;
有什么想法可能导致这种情况吗?我发誓今天早上我醒来它工作,下班回家,什么都没有。直接测试网站,工作正常。