I am getting this error when using curl extensions Curl error: Could not resolve host: http://rss.news.yahoo.com; No data record of requested type
<?php
ini_set("display_errors", 1);
error_reporting(E_ALL);
define ('HOSTNAME', 'http://rss开发者_C百科.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);
?>
Any ideas?
http://rss.news.yahoo.com/rss/world
is not a hostname. The host part is rss.news.yahoo.com
.
That said, your code works (what what's commented left commented). See http://codepad.viper-7.com/j1U3jC
Tim makes a good point. You should not make a POST request. Even if it "works", it interferes with the ability to cache the request.
精彩评论