php - file_get_contents 无法打开流 : HTTP request failed only for SPECIFIC web page

标签 php curl file-get-contents

尝试对特定 URL 执行 file_get_contents 时出现以下错误:http://lolking.net/champions/ 。我在尝试过的任何其他网页上执行 file_get_contents 时都没有遇到任何问题。

错误是:

警告:file_get_contents(http://lolking.net/champions) [function.file-get-contents]:无法打开流:HTTP 请求失败!

我认为该页面有意阻止我尝试发出的请求。我还尝试过使用 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;

关于php - file_get_contents 无法打开流 : HTTP request failed only for SPECIFIC web page,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22276378/

相关文章:

javascript - 如何编写一个 Node.js Express 服务器来接收 curl POST

api - curl LinkedIn API

php5 curl : Recompiling does not reflect in phpinfo

php - 无法通过 HTTPS 获取 file_get_contents 或 cURL

php - 来自 url 的 file_get_contents 只能在登录网站后访问

php - Yii2,Kartik DepDrop 更新预选值

php - PHP 如何取消 RabbitMQ 中的消费者?

javascript - Fullcalendar js 和 Firefox 中的日期无效,如何处理?

php - 使用 url var 下载文件 Curl

php - file_get_contents 在生产服务器上不工作,在本地很好