我一直在与这个斗争几个小时我现在正在尝试从maxhire中检索rss feed: rsslink,解析内容并使用jfeed显示它。现在我知道ajax不允许交叉域,我一直在使用jfeed打包的proxy.php,但无济于事只是告诉我网址中有很多重定向所以我增加了它们就像这样:
<?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了:
$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页面,但它只返回对象移动的相同错误:
<body>string(237) "<title>Object moved</title>
<h2>Object moved to <a href="/cp/?EC5A6C361E43515B7A591C6539&L=EN&AspxAutoDetectCookieSupport=1&AspxAutoDetectCookieSupport=1">here</a>.</h2>
"
</body>
然后将我重定向到本地的URL:&amp; AspxAutoDetectCookieSupport = 1添加到最后。 有人可以解释一下我做错了吗?
答案 0 :(得分:0)
正确我设法通过伪造useragent和cookies来使curl工作,我在wordpress中使用自定义元字段来分配这样的URL:
<?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;
}
?>