drpmazn9021 2015-03-19 19:14
浏览 34

curl在YouTube中没有匹配 - 返回null

But another server returns content normally..

$URL = http://www.youtube.com/get_video_info?&video_id='.$this->VideoId.'&asv=3&el=detailpage&hl=en_US


function curlGet($URL) {

$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; rv:19.0) Gecko/20100101 Firefox/19.0');
curl_setopt($ch, CURLOPT_URL, $URL);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); 

$contents = curl_exec($ch);

if(curl_errno($ch)) {
    echo ' er: ' . curl_error($ch)  ;
}
    // get content
    echo $contents ;
    curl_close($ch);
}
  • 写回答

1条回答 默认 最新

  • doujiao8491 2015-03-19 19:46
    关注

    Set the options to see the Request and Response headers.
    It is a good idea to include CURLOPT_FOLLOWLOCATION if your url is redirected.

    Something like this will help find problems.

     $ch = curl_init($url);
      curl_setopt($ch, CURLOPT_HEADER, true);
      curl_setopt($ch, CURLINFO_HEADER_OUT, true);
      curl_setopt($ch, CURLOPT_VERBOSE, true);
      curl_setopt($ch, CURLOPT_FAILONERROR,true);
      curl_setopt($ch, CURLOPT_AUTOREFERER, true);
    
      curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    
      curl_setopt($ch, CURLOPT_ENCODING,"");
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
      curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
      curl_setopt($ch, CURLOPT_FILETIME, true);
      curl_setopt($ch, CURLOPT_USERAGENT,"Mozilla/5.0 (Windows NT 5.1; rv:32.0) Gecko/20100101 Firefox/32.0");
      curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 100);
      curl_setopt($ch, CURLOPT_TIMEOUT,100);
      $data = curl_exec($ch);
      if (curl_errno($ch)){
          $data .= 'Retreive Base Page Error: ' . curl_error($ch);
      }
      else {
        $skip = intval(curl_getinfo($ch, CURLINFO_HEADER_SIZE)); 
        $responseHeader = substr($data,0,$skip);
        $data= substr($data,$skip);
        $info = curl_getinfo($ch);
        $info = var_export($info,true);
      }
      echo $responseHeader;
      echo $info;
      print_r($data);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)