get html content of a page with Silverlight
- by Yustme
Hi,
I'm trying to get the html content of a page using silverlight. Webresponse and request classes don't work in silverlight.
I did some googling and I found something. This is what i tried:
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.
}
}
It gives me a runtime error after pressing the button:
Microsoft JScript runtime error: Unhandled Error in Silverlight Application An exception occurred during the operation, making the result invalid. Check InnerException for exception details. at System.ComponentModel.AsyncCompletedEventArgs.RaiseExceptionIfNecessary()
at System.Net.DownloadStringCompletedEventArgs.get_Result()
at JWTG.MainPage.ClientDownloadStringCompleted(Object sender, DownloadStringCompletedEventArgs e)
at System.Net.WebClient.OnDownloadStringCompleted(DownloadStringCompletedEventArgs e)
at System.Net.WebClient.DownloadStringOperationCompleted(Object arg)
I've tried numerous things but all failed.
What am i missing? Or does anyone know how i could achieve this in a different way?
Thanks in advance!