WebClient doesn't exist on Windows Phone 8.1? Downloading html of site

前端 未结 3 1814
攒了一身酷
攒了一身酷 2021-01-14 07:39

I want to get source code of some website.

I found this solution:

var html = System.Net.WebClient().DownloadString(siteUrl);

But Vi

3条回答
  •  佛祖请我去吃肉
    2021-01-14 08:20

    WebClient does exist in WP8 like this:

    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 something like this:

        HttpClient http = new System.Net.Http.HttpClient();
        HttpResponseMessage response = await http.GetAsync("somesite");
        webresponse = await response.Content.ReadAsStringAsync();
    

提交回复
热议问题