windows phone WebClient doesn't work

325 views Asked by At
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?

1

There are 1 answers

4
dev_ankit On

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