WebClient client = new WebClient();
When I try do to something like that I get an error
Error 2 The type or namespace name 'WebClient' does not exist in the namespace 'System.Net' (are you missing an assembly reference?)
What's wrong?
It is available in WP8 Silverlight projects. I prefer to use Windows.Web.Http.HttpClient
instead.
public async Task<String> myFunction(){
HttpClient httpClient = new HttpClient();
String response = await httpClient.GetStringAsync(
new Uri("http://www.example.com")
);
return response;
}
To use the function you will again use await.
String data= await myFunction()
and so on...
You might need to install Microsoft HTTP Client Libraries from nuget
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.