我们已经谁使用Flash开发者调用一个名为proxy.php文件与查询字符串的URL =“HTTP:// Feedburner的/不管”?RSS种子,访问外部数据从结构域默认情况下不从SWF代码访问。例如,我可以在浏览器中执行以下操作: HTTP://localhost/proxy.php ?URL = feedburner.com / a_feed 和浏览器将显示页面,如果我直接把XML网址在浏览器地址栏中。在此proxy.php文件的PHP代码如下。

$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_POSTFIELDS, $post_data);
}

$response = curl_exec($ch);     

if (curl_errno($ch)) {
    print curl_error($ch);
} else {
    curl_close($ch);
    //$response=split("iso-8859-2",$response);
    //$response=join("UTF-8",$response);
    print $response;
}

它工作正常,但由于托管限制,我们需要复制在asp.net的功能。我不知道PHP,尽管努力了解我惨遭失败的代码。我需要的是能够复制我在asp.net第一段但尽管谷歌搜索,并试图我失败了一个ashx的文件中与XmlTextWriter的技术描述的功能。我缺少的是在这里吗?

我猜一个Response.Redirect的是行不通的,因为它告诉源去外域本身,我们希望避免这种情况。

我将如何在ASP.NET中实现这个PHP代码的功能?

有帮助吗?

解决方案

所有他做的是调用CURL这是一个HTTP客户端(除其他事项外)来下载文件,然后流出来了回应。你可以通过调用HttpWebRequest的复制功能。有一个教程这里:

http://support.microsoft.com/kb/303436

其他提示

在情况下,有人想代码片段,基于该链接我写了下面的代码上,它不只是招(显然,这是硬编码的,但现在哎...):

protected void Page_Load(object sender, EventArgs e)
{
    string URL = "http://feeds2.feedburner.com/the-foreigner";
    HttpWebRequest HttpWRequest = (HttpWebRequest)WebRequest.Create(URL);
    HttpWebResponse HttpWResponse = (HttpWebResponse)HttpWRequest.GetResponse();

    //Read the raw HTML from the request
    StreamReader sr = new StreamReader(HttpWResponse.GetResponseStream(), Encoding.ASCII);
    //Convert the stream to a string
    string s = sr.ReadToEnd();
    sr.Close();
    Response.Write(s); 
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top