小编Yus*_*tme的帖子

使用Silverlight获取页面的html内容

我正在尝试使用silverlight获取页面的html内容.Web响应和请求类在Silverlight中不起作用.

我做了一些谷歌搜索,我发现了一些东西.这是我试过的:

public partial class MainPage : UserControl
 {
  string result;
  WebClient client;

  public MainPage()
  {
   InitializeComponent();
   this.result = string.Empty;
   this.client = new WebClient();
   this.client.DownloadStringCompleted += ClientDownloadStringCompleted;
  }

  private void btn1_Click(object sender, RoutedEventArgs e)
  {
   string url = "http://www.nu.nl/feeds/rss/algemeen.rss";

   this.client.DownloadStringAsync(new Uri(url, UriKind.Absolute));

   if (this.result != string.Empty && this.result != null)
   {
    this.txbSummery.Text = this.result;
   }
  }

  private void ClientDownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
  {
   this.result = e.Result;
   //handle the response.
  }
 }
Run Code Online (Sandbox Code Playgroud)

按下按钮后,它会给我一个运行时错误:

Microsoft JScript运行时错误:Silverlight应用程序中的未处理错误操作期间发生异常,导致结果无效.检查InnerException以获取异常详细信息.在System.ComponentModel.AsyncCompletedEventArgs.RaiseExceptionIfNecessary()在System.Net.DownloadStringCompletedEventArgs.get_Result()在JWTG.MainPage.ClientDownloadStringCompleted(对象发件人,DownloadStringCompletedEventArgs e)上System.Net.WebClient.OnDownloadStringCompleted(DownloadStringCompletedEventArgs e)上System.Net. WebClient.DownloadStringOperationCompleted(Object arg)

我尝试了很多东西,但都失败了.

我错过了什么?或者有谁知道我怎么能以不同的方式实现这一目标? …

html c# silverlight runtime

5
推荐指数
1
解决办法
6163
查看次数

标签 统计

c# ×1

html ×1

runtime ×1

silverlight ×1