file_get_contents,HTTP请求失败

时间:2014-03-11 01:33:34

标签: php httprequest file-get-contents

我尝试使用file_get_contents从其他网站获取内容,但我总是“无法打开流:HTTP请求失败!” allow_url_fopen已启用,我已关闭防火墙进行了测试。但它仍然会发生,还有其他原因吗?

编辑: 这是完整的信息 警告:file_get_contents(http://yemto.deviantart.com/):无法打开流:HTTP请求失败!在第15行的D:\ xampp \ htdocs \ deviantart \ webcam \ img.php

和代码

//Load the page into a DOMDocument
$file = file_get_contents(strToLower("http://".$user.".deviantart.com/"));//TO-DO <-- if deivantart name is empty, it crashes
$doc = new DOMDocument();
@$doc -> loadHTML($file);

1 个答案:

答案 0 :(得分:6)

如果客户端未发送User-Agent标头,您的网络服务器会立即关闭连接。尝试在user_agent添加php.ini选项,或者添加:

ini_set('user_agent', 'PHP');

在你的剧本中。

相关问题