2011-11-07 52 views
1

我試圖加載與jQuery和(ASPX)代理遠程rss飼料。我在這個問題上讀了很多問題,但我的情況稍有不同。
我有一個XML文件,其中包含用戶的訂閱。對於每個條目我想加載一些飼料,比如前三個飼料。
我可以正確檢索訂閱列表,但我無法獲取訂閱源條目。代理一直給這個異常:代理ASP不加載外部xml

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提要?
任何幫助非常感謝!謝謝!

回答

1

我解決了這個問題。我認爲,如果你安裝IIS後,你安裝.NET 4 Asp不會註冊到IIS,所以你總是得到error 500(也許這對於以前版本的IIS也是如此,但我不能檢查這一點)。 解決的辦法是打開命令行(我一樣管理員)和移動到文件夾:

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

現在你應該是好去,享受!

+1

[MSDN](http://www.varindersandhu.in/2010/12/13/asp-net-iis-registration-tool-aspnet_regiis-exe/),有關此工具的更多信息。很高興知道,謝謝! –

3

這看起來更像網絡/連接問題,而不是代碼中的錯誤。

您可以手動連接到提要的網址嗎?也許有些代理阻止訪問到他們...

一些言論:

  • 做這些行業的工作經驗,最好使用HttpHandlers的,而不是aspx頁面,以避免全(和時間/資源消耗)Page Lifecycle。在Encosia here上有一篇非常有趣的文章。

  • 最好是使用jquery ajax選項對象的data屬性來傳遞數據,而不是像當前那樣構造查詢字符串。

希望這會有所幫助,d。

+0

感謝您的HttpHandler建議。我切換到它,因爲它似乎是我正在尋找!對於這個問題,請閱讀我的答案。 – andreapier