【问题标题】:proxy asp does not load external xml代理 asp 不加载外部 xml
【发布时间】:2011-12-23 11:17:12
【问题描述】:

我正在尝试使用 jquery 和 (aspx) 代理加载远程 rss 提要。我阅读了很多关于这个问题的问题,但我的问题略有不同。
我有一个包含用户订阅的 XML 文件。对于每个条目,我想加载一些提要,比如前 3 个提要。
我可以正确检索订阅列表,但无法获取提要条目。代理不断给出这个异常:

Riga 22:             HttpWebRequest request = (HttpWebRequest) WebRequest.Create(proxyURL);
Riga 23:             request.Method = "GET";
Riga 24:             HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Riga 25: 
Riga 26:             if (response.StatusCode.ToString().ToLower() == "ok")

[SocketException (0x274c): Impossibile stabilire la connessione. Risposta non corretta della parte connessa dopo l'intervallo di tempo oppure mancata risposta dall'host collegato 213.92.16.191:80]


System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress) +269
   System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Int32 timeout, Exception& exception) +649

[WebException: Impossibile effettuare la connessione al server remoto.]
   System.Net.HttpWebRequest.GetResponse() +1126
   Proxy.Page_Load(Object sender, EventArgs e) in c:\Users\andrea\documents\visual_studio_2010\websites\leafhouse\Proxy.aspx.cs:24
   System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +25
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +42
   System.Web.UI.Control.OnLoad(EventArgs e) +132
   System.Web.UI.Control.LoadRecursive() +66
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2428

这是我的 proxy.aspx 页面:

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.IO;

public partial class Proxy : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string proxyURL = string.Empty;
        try
        {
            proxyURL = HttpUtility.UrlDecode(Request.QueryString["u"].ToString());

        if (proxyURL != string.Empty)
        {
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(proxyURL);
            request.Method = "GET";
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();

            if (response.StatusCode.ToString().ToLower() == "ok")
            {
                string contentType = response.ContentType;
                Stream content = response.GetResponseStream();
                StreamReader contentReader = new StreamReader(content);
                Response.ContentType = contentType;
                Response.Write(contentReader.ReadToEnd());
            }
        }
    }
    catch(Exception ex)
    {
        Console.WriteLine(ex.Message);
    }
}

}

这是我使用的 jquery:

$.ajax({
    type: "GET",
    url: "proxy.aspx?u=" + encodeURI("http://" + serverAddress + ":82") + "/RSSReaderSubscriptions.xml",
    dataType: "xml",
    success: function (data) {
        $(data).find('url').each(function (index, element) {
            if (index < 3) {
                $.ajax({
                    type: "GET",
                    url: "proxy.aspx?u=" + encodeURI($(this).text()),
                    dataType: "xml",
                    success: function (data) {
                        parseRSS(data);
                    },
                    error: function () {
                        console.log("error");
                });
            }
        });
    },
    error: function () {
        console.log("error");
});

如何让代理加载 RSS 源?
任何帮助是极大的赞赏!谢谢!

【问题讨论】:

    标签: c# jquery asp.net xml rss


    【解决方案1】:

    我解决了这个问题。我认为,如果您在安装 .NET 4 Asp 之后安装 IIS,则不会将自身注册到 IIS,因此您总是会得到 error 500(对于以前的 IIS 版本可能也是如此,但我无法检查)。 解决方案是打开命令行(我以管理员身份)并移动到文件夹:

    cd %windir%/Microsoft.NET/Framework/v4.xxxxx/
    aspnet_regiis.exe -i
    

    现在你应该可以开始了,享受吧!

    【讨论】:

    • 这里有更多关于这个工具的信息MSDN。很高兴知道,也谢谢!
    【解决方案2】:

    这看起来更像是网络/连接问题,而不是代码中的错误。

    您可以“手动”连接到提要的网址吗?也许某些代理阻止了对它们的访问...

    一些备注:

    • 要完成此类工作,最好使用 HttpHandlers 而不是 aspx 页面,以避免完整(和时间/资源消耗)Page Lifecycle。在 Encosia here 上有一篇非常有趣的文章。

    • 最好使用 jquery ajax 选项对象的data 属性来传递数据,而不是像现在这样构造查询字符串。

    希望这会有所帮助,d。

    【讨论】:

    • 感谢 HttpHandler 的建议。我切换到它,因为它似乎是我正在寻找的东西!对于这个问题,请阅读我的回答。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-09-28
    • 1970-01-01
    • 1970-01-01
    • 2018-12-01
    • 1970-01-01
    • 2011-01-19
    • 1970-01-01
    相关资源
    最近更新 更多