Warning: file_get_contents(http://news.163.com/special/00013C0B/gedixw.html) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in F:\wamp\www\jxcms\test.php on line 2

解决方案 »

  1.   

    $url = 'http://news.163.com/special/00013C0B/gedixw.html';
    $ch = curl_init();curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //获得返回内容,但不需要直接输出到页面上
    curl_setopt($ch, CURLOPT_TIMEOUT, 30); //时间延迟
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);$output = curl_exec($ch); //执行,并接收返回的内容
    curl_close($ch);
    echo $output;
      

  2.   

    $url = 'http://news.163.com/special/00013C0B/gedixw.html';
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    $output = curl_exec($ch);
    curl_close($ch);
    echo $output;
      

  3.   

    $url = 'http://news.163.com/special/00013C0B/gedixw.html';
    $tmp = parse_url($url);
    $host = $tmp['host'];
    $port = $tmp['port'];
    $path = $tmp['path'];
    $tmp['query'] && $path .= '?' . $tmp['query'];
    if (empty($port))$port = 80;
    elseif ($tmp['scheme'] == 'https') $port = 443;
    elseif ($tmp['scheme'] == 'http') $port = 80;
    $fp = @fsockopen($host, $port, $errno, $errstr);
    $data = '';
    if (!$fp) {
    echo "$errstr ($errno)<br />\n";
    } else {
    $user_agent = $_SERVER['HTTP_USER_AGENT'];
    $tmp = "GET $path HTTP/1.1\r\n";
    $tmp .= "Host: $host\r\n";
    $tmp .= "User-Agent: $user_agent\r\n";
    $tmp .= "Connection: Close\r\n\r\n";
    fwrite($fp , $tmp);
    while (!feof($fp)) $data .= fgets($fp, 1024);
    $data = trim(substr($data, strpos($data, "\r\n\r\n") + 4));
    fclose($fp);
    }echo $data;这样可以,不知道是不是过段时间也会被封
      

  4.   

    加个referer信息,看能不能骗过去.
      

  5.   

    function get_request($url, $query_str)
    {
        $query_str = preg_replace('/^&/', '', $query_str);
        $url = $url.'?'.$query_str;
        $context =  array('http' =>
                           array('method' => 'GET',
                                 'header' => 'User-Agent:Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 2.0.50727)'
                           )
                      );
        $contextid = stream_context_create($context);
        $sock = fopen($url, 'r', false, $contextid);
        if($sock)
        {
             $result = '';
             while (!feof($sock))
             {
                 $result .= fgets($sock, 4096);
             }
               fclose($sock);
        }
        return array(0, $result);
    }
    $arr = get_request('http://news.163.com/special/00013C0B/gedixw.html', '');
    print_r( $arr );测试通过
      

  6.   

    你用curl伪装成浏览器看看,如果他用javascript加载的话,就郁闷了
      

  7.   

    直接在Linux下Curl呢
    再不行
    看看后台用Java写个呢
      

  8.   

    我自己5楼的,也不比9楼的差啊!我的也测试通过的!主要是我做的精迅CMS,里面的采集例子,就是拿网易开刀的,结果过了一段时间,网易就把file_get_contents给搞没用了!