卷曲请求失败

发布于 2024-11-18 02:29:34 字数 1390 浏览 1 评论 0原文

我有一个小问题。我想使用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

辞取 2024-11-25 02:29:34

这是您的问题:$ur='http://www.facebook.com/feeds/page.php?id=57084011597&format=rss20';。你少了一个“l”。

$url='http://www.facebook.com/feeds/page.php?id=57084011597&format=rss20';

另外,还有一个重定向,因此您需要添加:

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

这就是我发现的。我使用 curl_setopt($ch, CURLOPT_VERBOSE, true); 启用了详细输出,并看到了以下内容:

< HTTP/1.1 302 Found
< Location: http://www.facebook.com/common/browser.php
< Content-Type: text/html; charset=utf-8
< X-FB-Server: 10.43.97.37
< X-Cnection: close
< Date: Thu, 30 Jun 2011 06:48:54 GMT
< Content-Length: 0

更新、测试和工作:

Facebook 期望指定用户代理字符串。用 curl_setopt($ch, CURLOPT_USERAGENT, '...'); 设置它似乎可以解决问题。这是一个过于简单的示例,应该可以解决您的问题:

<?php

$ch = curl_init('http://www.facebook.com/feeds/page.php?id=57084011597&format=rss20');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, array('User-Agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Safari/534.45'));

$response = curl_exec($ch);

This is your problem: $ur='http://www.facebook.com/feeds/page.php?id=57084011597&format=rss20';. You're missing an "l".

$url='http://www.facebook.com/feeds/page.php?id=57084011597&format=rss20';

Also, there's a redirect so you'll need to add:

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

This how I found out. I enabled verbose output using curl_setopt($ch, CURLOPT_VERBOSE, true); and saw this:

< HTTP/1.1 302 Found
< Location: http://www.facebook.com/common/browser.php
< Content-Type: text/html; charset=utf-8
< X-FB-Server: 10.43.97.37
< X-Cnection: close
< Date: Thu, 30 Jun 2011 06:48:54 GMT
< Content-Length: 0

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:

<?php

$ch = curl_init('http://www.facebook.com/feeds/page.php?id=57084011597&format=rss20');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, array('User-Agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Safari/534.45'));

$response = curl_exec($ch);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文