下面这个地址我用file_get_contents取不到内容,而在浏览器里是可以打开的
$content=file_get_contents('http://istock.jrj.com.cn/d/ht/hottopic1.html');
$content=file_get_contents('http://istock.jrj.com.cn/d/ht/hottopic1.html');
看看防火墙有没冇封锁
allow_url_fopen 是否为on
如果不是,重启apache.
另外,别的页面都可以取到的,就这个页面取不到
你header 一定要指的的一些 User-Agent 才给下载
否则 HTTP 503
$queryURL = "http://istock.jrj.com.cn/d/ht/hottopic1.html";
//user_agent
$useragent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)";
//伪造header
$header = array('Accept-Language: zh-cn','Connection: Keep-Alive','Cache-Control: no-cache');
$ch = curl_init();
curl_setopt($ch, CURLOPT_REFERER, $queryURL);
curl_setopt($ch,CURLOPT_HTTPHEADER,$header);
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
curl_setopt($ch, CURLOPT_URL,$queryURL);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
echo $result; 用这种方式获取吧.
应该是对方服务器做了限制.
用file_get_contents类函数返回HTTP request failed! HTTP/1.1 503 Service Temporarily Unavailable错误,MS是
allow_url_fopen 是否为on
如果不是,重启apache.
'http'=>array(
'method'=>"GET",
'header'=>"User-Agent: Mozilla/5.0\n"
)
);
$context = stream_context_create($opts);
echo file_get_contents("http://istock.jrj.com.cn/d/ht/hottopic1.html",false,$context);