首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用jfeed和curl检索rss提要?

使用jfeed和curl检索rss提要?
EN

Stack Overflow用户
提问于 2013-05-23 07:17:41
回答 1查看 307关注 0票数 0

我已经和这个问题斗争了几个小时了,现在我正试图从maxhire检索一个rss:rsslink,解析内容并使用jfeed显示它。现在我意识到ajax不允许跨域,我一直在使用jfeed附带的proxy.php,但无济于事,它只是告诉我url中有很多重定向,所以我像这样增加了它们:

代码语言:javascript
复制
<?php
header('Content-type: text/html');
$context = array(
    'http'=>array('max_redirects' => 99)
);
$context = stream_context_create($context);
// hand over the context to fopen()
$handle = fopen($_REQUEST['url'], "r", false, $context);

if ($handle) {
    while (!feof($handle)) {
        $buffer = fgets($handle, 4096);
        echo $buffer;
    }
    fclose($handle);
}
?>

但仍然不走运,它只是返回一条消息,告诉我对象已被移动。因此,我继续使用curl,如下所示:

代码语言:javascript
复制
$ch = curl_init('http://www.maxhire.net/cp/?EC5A6C361E43515B7A591C6539&L=EN');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, false);

$result = curl_exec($ch);
var_dump($result);

在本地检索xml页面,但返回的错误与对象移动的错误相同:

代码语言:javascript
复制
<body>string(237) "<title>Object moved</title>
<h2>Object moved to <a href="/cp/?EC5A6C361E43515B7A591C6539&amp;L=EN&amp;AspxAutoDetectCookieSupport=1&amp;AspxAutoDetectCookieSupport=1">here</a>.</h2>

"
</body>

然后将我重定向到本地url,并在末尾添加:&AspxAutoDetectCookieSupport=1。有人能解释一下我做错了什么吗?

EN

回答 1

Stack Overflow用户

发布于 2013-05-23 21:30:46

好的,我通过伪造用户代理和cookie设法让curl正常工作,我在wordpress中使用了一个自定义的元域来分配url,如下所示:

代码语言:javascript
复制
    <?php
  $mykey_values = get_post_custom_values('maxhireurl');
  foreach ( $mykey_values as $key => $value ) {  
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $value);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.6 (KHTML, like Gecko) Chrome/16.0.897.0 Safari/535.6'); 
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie.txt");
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_REFERER, "http://www.maxhire.net");
$html = curl_exec($ch);
curl_close($ch);
echo $html;
}
?>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16703102

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档