php:用cURL获取url内容(json)

我想用cURL访问https://graph.facebook.com/19165649929?fields=name(显然它也可以用“http”访问)来获取文件内容,更具体:我需要“名称”(它是json).
由于我的网络服务器上禁用了allow_url_fopen,因此我无法使用get_file_contents!所以我这样试了:

<?PHP
$page = 'http://graph.facebook.com/19165649929?fields=name';
$ch = curl_init();
//$useragent="Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1";
//curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
curl_setopt($ch, CURLOPT_URL, $page);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
?>

使用该代码,我得到一个空白页面!当我使用另一个页面时,如http://www.google.com,它就像一个魅力(我得到页面内容).我猜facebook正在检查一些我不知道的东西……它有什么用?如何使代码工作?谢谢!

解决方法:

在这里发帖了吗?
php: Get html source code with cURL

但是在上面的帖子中我们发现你的问题无法解决主机,这就是解决方案:

//$url = "https://graph.facebook.com/19165649929?fields=name";
$url = "https://66.220.146.224/19165649929?fields=name";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Host: graph.facebook.com'));
$output = curl_exec($ch);
curl_close($ch); 

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...