因此,我需要从公共API检索XML,但我的应用程序在Flash中,公共服务不会实现crossdomain.xml文件。我在网上找到了这个PHP脚本(见下文),以便代理请求URL。它工作正常的网址,如:PHP代理获取XML:URL参数问题
http://mysite.com/xml_proxy.php?url=http://rss.cnn.com/rss/cnn_topstories.rss
但脚本似乎无论带或忽略对URL的任何参数,如:
http://mysite.com/xml_proxy.php?url=http://publicapiserver.com?app_ID=35235x&app_key=84x
我PHP无知。有没有简单的方法让这个脚本处理这些URL参数?非常感谢。下面是该脚本:
<?php
$post_data = $HTTP_RAW_POST_DATA;
$header[] = "Content-type: text/xml";
$header[] = "Content-length: ".strlen($post_data);
$ch = curl_init($_GET['url']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
if (strlen($post_data)>0){
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
}
$response = curl_exec($ch);
$response_headers = curl_getinfo($ch);
if (curl_errno($ch)) {
print curl_error($ch);
} else {
curl_close($ch);
header('Content-type: ' . $response_headers['content-type']);
print $response;
}
?>
噢,伙计......这非常有意义。谢谢。 – Gregir 2011-02-17 21:14:22