卷曲请求失败
我有一个小问题。我想使用curl加载此页面'http://www.facebook.com/feeds/page.php?id=57084011597&format=rss20'。这是我尝试使用的代码,但我无法从中得到任何信息。
$head=array('Accept'=>'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Charset'=>'ISO-8859-2,utf-8;q=0.7,*;q=0.3',
'Accept-Encoding'=>'gzip,deflate,sdch',
'Accept-Language'=>'ro-RO,ro;q=0.8,en-US;q=0.6,en;q=0.4',
'Cache-Control'=>'max-age=0',
'Connection'=>'keep-alive',
'Cookie'=>'datr=hroHTi2NZk2KleOaswb03Q_Q; lu=gg9lJcPeInHt6hnut7bviqQg; locale=en_US; e=n; L=2; c_user=100000596376783; sct=1309129360; xs=2%3Ad05dd80e364608525dd664ad73f6483f; act=1309410851554%2F5; presence=EM309410852L4N0_5dEp_5f1B00596376783F1X309410852168Y0Z11G309410768PCC',
'Host'=>'www.facebook.com',
'User-Agent'=>$_SERVER['HTTP_USER_AGENT']);
$url='http://www.facebook.com/feeds/page.php?id=57084011597&format=rss20';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
curl_setopt($ch, CURLOPT_HTTPHEADER,$head);
$result = curl_exec($ch);
return $result;
我尝试过不设置标题,但也没有成功。 希望有人能给我一个线索。
谢谢你!
I have a small issue. I want to load this page 'http://www.facebook.com/feeds/page.php?id=57084011597&format=rss20' using curl. Here is the code I am trying t use, nut I can't get aything back from it.
$head=array('Accept'=>'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Charset'=>'ISO-8859-2,utf-8;q=0.7,*;q=0.3',
'Accept-Encoding'=>'gzip,deflate,sdch',
'Accept-Language'=>'ro-RO,ro;q=0.8,en-US;q=0.6,en;q=0.4',
'Cache-Control'=>'max-age=0',
'Connection'=>'keep-alive',
'Cookie'=>'datr=hroHTi2NZk2KleOaswb03Q_Q; lu=gg9lJcPeInHt6hnut7bviqQg; locale=en_US; e=n; L=2; c_user=100000596376783; sct=1309129360; xs=2%3Ad05dd80e364608525dd664ad73f6483f; act=1309410851554%2F5; presence=EM309410852L4N0_5dEp_5f1B00596376783F1X309410852168Y0Z11G309410768PCC',
'Host'=>'www.facebook.com',
'User-Agent'=>$_SERVER['HTTP_USER_AGENT']);
$url='http://www.facebook.com/feeds/page.php?id=57084011597&format=rss20';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
curl_setopt($ch, CURLOPT_HTTPHEADER,$head);
$result = curl_exec($ch);
return $result;
I've tried without setting a header but it also didn't worked.
Hope that somebody coud give me a clue.
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是您的问题:
$ur='http://www.facebook.com/feeds/page.php?id=57084011597&format=rss20';
。你少了一个“l”。另外,还有一个重定向,因此您需要添加:
这就是我发现的。我使用
curl_setopt($ch, CURLOPT_VERBOSE, true);
启用了详细输出,并看到了以下内容:更新、测试和工作:
Facebook 期望指定用户代理字符串。用
curl_setopt($ch, CURLOPT_USERAGENT, '...'); 设置它似乎可以解决问题。这是一个过于简单的示例,应该可以解决您的问题:
This is your problem:
$ur='http://www.facebook.com/feeds/page.php?id=57084011597&format=rss20';
. You're missing an "l".Also, there's a redirect so you'll need to add:
This how I found out. I enabled verbose output using
curl_setopt($ch, CURLOPT_VERBOSE, true);
and saw this:Update, tested and working:
Facebook expects a user-agent string to be specified. Setting it with
curl_setopt($ch, CURLOPT_USERAGENT, '...');
seems to solve the problem. Here's an over-simplistic example which should solve your problem: