I have this cUrl request that works sometimes, then stops working. I am echoing the header and any errors, http shows 200 ok and no errors, but content length is 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;
Any ideas what could cause this? I swear this morning I woke up it worked, got home from work, nothing. Tested the site directly, works fine.