0

我正在尝试从 Silverlight 中的网页获取源代码。

这是我的代码

        WebClient wc = new WebClient();
        wc.DownloadStringCompleted += new DownloadStringCompletedEventHandler(WebClient_DownloadStringCompleted);
        wc.DownloadStringAsync(new Uri("http://ip-whois-lookup.com/lookup.php?ip=19.118.245.124"));


    void WebClient_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
    {
        if (e.Error == null)
        {
            Mytext.Text = e.Result.ToString();
        }
        else
            Mytext.Text = e.Error.ToString();
    }

这是我的错误。

System.Security.SecurityException ---> System.Security.SecurityException: Security error.
   at System.Net.Browser.BrowserHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult)
   at System.Net.Browser.BrowserHttpWebRequest.<>c__DisplayClassa.<EndGetResponse>b__9(Object sendState)
   at System.Net.Browser.AsyncHelper.<>c__DisplayClass4.<BeginOnUI>b__0(Object sendState)
   --- End of inner exception stack trace ---
   at System.Net.Browser.AsyncHelper.BeginOnUI(SendOrPostCallback beginMethod, Object state)
   at System.Net.Browser.BrowserHttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
   at System.Net.WebClient.GetWebResponse(WebRequest request, IAsyncResult result)
   at System.Net.WebClient.DownloadBitsResponseCallback(IAsyncResult result)

相同 url 的相同原理适用于 ac# 控制台应用程序

 string htmlContent = new System.Net.WebClient().DownloadString("http://ip-whois-lookup.com/lookup.php?ip=19.118.245.124");

我正在寻找的是能够使用我选择的任何 ip 更改该 url 中的 ip 并获取该页面的源代码。

在 silverlight 中给出错误的相同代码适用于其他网站:例如:http ://tcpiputils.com/browse/ip-address/79.118.20.240、http: //livescore.com,但也不适用于 google。 com,也许还有其他人。

4

1 回答 1

3

您的代码有效,因为该站点(tcputils.com、livescore.com)在根目录中有 crossdomain.xml 文件(例如http://livescore.com/crossdomain.xml)。该文件基本上是一个允许从外部站点 Web 域访问站点数据的选项。

如果文件丢失(例如,在网站http://ip-whois-lookup.com/上),来自 silverlight 应用程序的请求将不起作用。这是silverlight 安全限制。

于 2013-01-27T12:32:30.077 回答