I am having a bit of an issue in using WebClient on Windows Phone 7. I am currently trying to use it by downloading a file into a string so that I can parse the string using JSON.NET. Unfortunately, I am can't even seem to get the file into a string just yet. Here is my code:
private void GetFileAsString()
{
var client = new WebClient();
client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(sClient_DownloadStringCompleted);
client.DownloadStringAsync(new Uri(searchData.searchurl, UriKind.Relative));
}
private void sClient_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
if (e.Error == null)
{
textBlock1.Text = e.Result;
}
else
{
textBlock1.Text = e.Error.ToString();
}
}
And here is a screenshot of the error I am receiving: http://k.min.us/jzvIAYJ18uQbV.png
I've looked online quite a bit and can't seem to find a solution to this problem, including in previous posts on this site. Any help here is greatly appreciated!
You need to setup BaseAddress
property on your WebClient
instance correctly when you use UriKind.Relative
, alternatively just use absolute Uri
- otherwise it tries to use your xap's origin Uri
...