C# 网络客户端不';Windows Phone 8.1上不存在吗?下载网站的html
我想得到一些网站的源代码 我找到了这个解决方案:C# 网络客户端不';Windows Phone 8.1上不存在吗?下载网站的html,c#,windows,windows-phone,windows-phone-8.1,C#,Windows,Windows Phone,Windows Phone 8.1,我想得到一些网站的源代码 我找到了这个解决方案: var html = System.Net.WebClient().DownloadString(siteUrl); 但是VisualStudio告诉我们System.Net中不存在WebClient 如何解决这个问题?或者如何以另一种方式进行 PS:windows phone是否有一些特殊的标签,开发者在寻找一些代码/解决方案时通常会使用这些标签?WebClient可用于windows phone Silverlight 8.1应用程序。 W
var html = System.Net.WebClient().DownloadString(siteUrl);
但是VisualStudio告诉我们System.Net中不存在WebClient
如何解决这个问题?或者如何以另一种方式进行
PS:windows phone是否有一些特殊的标签,开发者在寻找一些代码/解决方案时通常会使用这些标签?WebClient可用于windows phone Silverlight 8.1应用程序。 Windows Phone运行时应用程序使用
WP8中还存在一个类似以下内容的网络客户端:
WebClient thisclient = new WebClient();
thisclent.DownloadStringAsync(new Uri("urihere");
thisclient.DownloadStringCompleted += (s, x) =>
{
if (x.Error != null)
{
//Catch any errors
}
//Run Code
}
HttpClient http = new System.Net.Http.HttpClient();
HttpResponseMessage response = await http.GetAsync("somesite");
webresponse = await response.Content.ReadAsStringAsync();
对于8.1应用程序,请使用以下内容:
WebClient thisclient = new WebClient();
thisclent.DownloadStringAsync(new Uri("urihere");
thisclient.DownloadStringCompleted += (s, x) =>
{
if (x.Error != null)
{
//Catch any errors
}
//Run Code
}
HttpClient http = new System.Net.Http.HttpClient();
HttpResponseMessage response = await http.GetAsync("somesite");
webresponse = await response.Content.ReadAsStringAsync();
这是我当前用于从网页下载HTML源代码的内容:
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;
}
}
公共静态异步任务下载PageAsync(字符串pageURL)
{
使用(HttpClient=new HttpClient())
使用(httpresponsemessageresponse=wait client.GetAsync(第页))
使用(HttpContent=response.content)
{
字符串结果=等待内容。ReadAsStringAsync();
返回结果;
}
}
此函数将返回已下载的pageURL的html。前几天我遇到了这个问题,所以我只是打电话进来。当谈到Silverlight时,WebClient(我相信其他类)有点精简了(我在使用cordova和一些C#for WP8)。