简体   繁体   中英

PHP - cURL request not working

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;

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'
);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM