Reputation: 71
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?
Upvotes: 0
Views: 315
Reputation: 536
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
Upvotes: 1