示例:http://www.whois.net/whois/hotmail.com
在浏览器中打开时,会显示输出。
使用curl call时,它什么也没显示。
怎么了?我想返回整页结果,然后使用正则表达式在到期日期检索数据:2015年3月29日00:00:00行。
$postfields= null;
$postfields["noneed"] = "";
$queryurl= "http://www.whois.net/whois/hotmail.com";
$results= getUrlContent($postfields, $queryurl);
echo $results;
function getUrlContent($postfields,$api_url)
{
if( !extension_loaded('curl') ){die('You need to load/activate the cURL extension (http://www.php.net/cURL).'); }
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $api_url); // set the url to fetch
curl_setopt($ch, CURLOPT_HEADER, 0); // set headers (0 = no headers in result)
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // type of transfer (1 = to string)
curl_setopt($ch, CURLOPT_TIMEOUT, 10); // time to wait in seconds
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
$content = curl_exec($ch); // make the call
curl_close($ch);
return $content;
}
答案 0 :(得分:3)
Whois.net检查user agent
。在调用curl_exec
$useragent="Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1";
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
答案 1 :(得分:1)
您看到的错误与whois.com无关,它表明您没有为PHP启用cURL模块。首先尝试启用PHP cURL模块。
如果您不确定如何启用PHP cURL模块,请遵循以下主题:How to enable cURL in PHP / XAMPP
希里什