<?php
ini_set("display_errors", 1);
error_reporting(E_ALL);
define ('HOSTNAME', 'http://rss.news.yahoo.com/rss/world');
//$path = ($_POST['rss_path']) ? $_POST['rss_path'] : $_GET['rss_path'];
//$url = HOSTNAME.$path;
$url = HOSTNAME;
// Open the Curl session
$session = curl_init();
curl_setopt($session, CURLOPT_URL, $url);
// If it's a POST, put the POST data in the body
/*
if (isset($_POST['rss_path'])) {
$postvars = '';
while ($element = current($_POST)) {
$postvars .= urlencode(key($_POST)).'='.urlencode($element).'&';
next($_POST);
}
curl_setopt ($session, CURLOPT_POST, true);
curl_setopt ($session, CURLOPT_POSTFIELDS, $postvars);
}
*/
curl_setopt ($session, CURLOPT_POST, true);
curl_setopt($session, CURLOPT_HEADER, false);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
$xml = curl_exec($session);
if(curl_errno($session)) {
echo 'Curl error: ' . curl_error($session);
}
header("Content-Type: text/xml");
echo $xml;
curl_close($session);
?>
有什么想法吗?
答案 0 :(得分:0)
http://rss.news.yahoo.com/rss/world
不是主机名。主持人部分是rss.news.yahoo.com
。
那就是说,你的代码可以正常工作(留下评论的内容)。见http://codepad.viper-7.com/j1U3jC
蒂姆提出了一个很好的观点。您不应该发出POST请求。即使它“有效”,它也会干扰缓存请求的能力。