HTTP请求失败! HTTP / 1.1 416请求的范围在php文件中不满意

时间:2015-01-18 14:26:49

标签: php wamp

我该如何解决这个错误 file_get_contents(http://www.example.com/name/j/92801): failed to open stream: HTTP request failed! HTTP/1.1 416 Requested Range Not Satisfiable in line
这是php文件代码 echo $file = file_get_contents("http://www.example.com/name/j/92801");
我正在使用wamp server 2.4

1 个答案:

答案 0 :(得分:1)

首先在php.ini文件中启用allow_url_fopen?第二个更好的使用CURL继承人有一点功能来帮助你

function curl($url , $ua = FALSE){
            if($ua == false){
                $ua = $_SERVER['HTTP_USER_AGENT'];
            }
            $ch = curl_init();
            curl_setopt($ch , CURLOPT_URL , $url);
            curl_setopt($ch , CURLOPT_RETURNTRANSFER , true);
            curl_setopt($ch , CURLOPT_FOLLOWLOCATION , true);
            curl_setopt($ch , CURLOPT_USERAGENT , $ua);
            return curl_exec($ch);
        }