doulifang5554
2014-10-16 07:22
浏览 281
已采纳

PHP - cURL请求不起作用

I'm trying to use cURL in PHP to retrieve the HTML of https://www.facebook.com/video.php?v=720617444660843, but it's not printing nothing and curl_error is returning nothing.

This is the code I'm using:

$defaults = array(
    CURLOPT_URL => "https://www.facebook.com/video.php?v=720617444660843",
    CURLOPT_HEADER => 0,
    CURLOPT_RETURNTRANSFER => TRUE,
    CURLOPT_TIMEOUT => 4
);

$ch = curl_init();
curl_setopt_array($ch, $defaults);
if( ! ($result = curl_exec($ch)))
{
    trigger_error(curl_error($ch));
}
curl_close($ch);
echo $result;

图片转代码服务由CSDN问答提供 功能建议

我正在尝试在PHP中使用cURL来检索 https://www.facebook的HTML .com / video.php?v = 720617444660843 ,但它没有打印, curl_error 什么都没有返回。

这是我的代码 使用:

  $ defaults = array(
 CURLOPT_URL =>“https://www.facebook.com/video.php?v=720617444660843",n  CURLOPT_HEADER => 0,
 CURLOPT_RETURNTRANSFER => TRUE,
 CURLOPT_TIMEOUT => 4 
); 
 
 $ ch = curl_init(); 
curl_setopt_array($ ch,$ defaults); 
if(!  ($ result = curl_exec($ ch)))
 {
 trigger_error(curl_error($ ch)); 
} 
curl_close($ ch); 
echo $ result; 
    
 
  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongnuo2879 2014-10-16 07:36
    已采纳

    You need to pass user agent

    $defaults = array(
    CURLOPT_URL => "https://www.facebook.com/video.php?v=720617444660843",
    CURLOPT_HEADER => 0,
    CURLOPT_RETURNTRANSFER => TRUE,
    CURLOPT_TIMEOUT => 4,
    CURLOPT_USERAGENT => 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.16 (KHTML, like Gecko) \ Chrome/24.0.1304.0 Safari/537.16'
    );
    
    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题