尝试file_get_contents
在特定的URL上执行时出现以下错误:http : //lolking.net/champions/。我file_get_contents
在尝试过的任何其他网页上执行都没有问题。
错误是:
Warning: file_get_contents(http://lolking.net/champions) [function.file-get-contents]: failed to open stream: HTTP request failed!
我认为该页面故意阻止了我要发出的请求。我也尝试过使用cURL并伪造用户代理,但是这些都不起作用。
我还有其他方法可以尝试从上述URL中获取信息吗?
这对我有用,请记住拥有cookies.txt。
$cookie_file = "cookies.txt";
$url = 'http://www.lolking.net/champions';
$c = curl_init($url);
curl_setopt($c, CURLOPT_FRESH_CONNECT, 1);
curl_setopt($c, CURLOPT_COOKIEJAR, $cookie_file);
curl_setopt($c, CURLOPT_COOKIEFILE, $cookie_file);
curl_setopt($c, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20100101 Firefox/17.0");
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_FOLLOWLOCATION, 1);
$z = curl_getinfo($c);
$s = curl_exec($c);
curl_close($c);
echo $s;
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句