duanque2413 2015-03-11 19:20
浏览 192

警告file_get_contents()无法打开流:HTTP请求失败! HTTP / 1.0 402需要付款

I got this error today but before that, my code was working fine.

The code is working fine on localhost but I get error on my website

Here is the line of code that produces the error:

$data = file_get_contents("https://www.youtube.com/get_video_info?hl=en&video_id={$_GET['id']}&eurl=&el=detailpage&gl=US&ps=default");

and the error:

Warning: file_get_contents(https://www.youtube.com/get_video_info?hl=en&video_id=SD3S27fMGzc&eurl=&el=detailpage&gl=US&ps=default): failed to open stream: HTTP request failed! HTTP/1.0 402 Payment Required in /home/zyxs/public_html/site.com/vid/youtube.php on line 2

  • 写回答

1条回答 默认 最新

  • drh19790711 2015-03-11 19:47
    关注

    Try this one

    function http_get_contents($url)
        {
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_TIMEOUT, 1);
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            if(FALSE === ($retval = curl_exec($ch))) {
                echo curl_error($ch);
            } else {
                return $retval;
            }
        }
    
        $request_url = 'http://gdata.youtube.com/feeds/api/videos/SD3S27fMGzc';
        $result = http_get_contents($request_url);
    
        $simpleXML = new SimpleXMLElement($result);
    
        print_r($simpleXML);
    
    评论

报告相同问题?