WebClient doesn't exist on Windows Phone 8.1? Loading html site
I want to get the source code of some website.
I found this solution:
var html = System.Net.WebClient().DownloadString(siteUrl);
But VisualStudio reports that WebClient does not exist in System.Net.
How to fix it? Or how to do it in another way?
PS: is there some special tag in Windows phone that developers usually use when looking for some code / solutions?
+3
source to share
3 answers
The WebClient exists in WP8 as follows:
WebClient thisclient = new WebClient();
thisclent.DownloadStringAsync(new Uri("urihere");
thisclient.DownloadStringCompleted += (s, x) =>
{
if (x.Error != null)
{
//Catch any errors
}
//Run Code
}
For 8.1 apps use the following:
HttpClient http = new System.Net.Http.HttpClient();
HttpResponseMessage response = await http.GetAsync("somesite");
webresponse = await response.Content.ReadAsStringAsync();
+12
source to share
WebClient is available for Windows Phone Silverlight 8.1 applications. Windows Phone Runtime Apps use Windows.Web.Http.HttpClient .
There is also a portable HttpClient for the .NET Framework and Windows Phone .
+3
source to share
This is what I am currently using to load HTML source from web pages:
public static async Task<string> DownloadPageAsync(string pageURL)
{
using (HttpClient client = new HttpClient())
using (HttpResponseMessage response = await client.GetAsync(page))
using (HttpContent content = response.Content)
{
string result = await content.ReadAsStringAsync();
return result;
}
}
This function will return the loaded html of the pageURL.
0
source to share