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

警告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);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 Python报错怎么解决
  • ¥15 simulink如何调用DLL文件
  • ¥15 关于用pyqt6的项目开发该怎么把前段后端和业务层分离
  • ¥30 线性代数的问题,我真的忘了线代的知识了
  • ¥15 有谁能够把华为matebook e 高通骁龙850刷成安卓系统,或者安装安卓系统
  • ¥188 需要修改一个工具,懂得汇编的人来。
  • ¥15 livecharts wpf piechart 属性
  • ¥20 数学建模,尽量用matlab回答,论文格式
  • ¥15 昨天挂载了一下u盘,然后拔了
  • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题