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

前端 未结 3 1773
攒了一身酷
攒了一身酷 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:18

    WebClient is available for Windows Phone Silverlight 8.1 apps. Windows Phone Runtime apps use Windows.Web.Http.HttpClient.

    There is also a Portable HttpClient for .NET Framework and Windows Phone.

    0 讨论(0)
  • 2021-01-14 08:18

    This is what I currently use to download HTML source from webpages:

    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;
            }
        }
    

    This function will return downloaded html of pageURL.

    0 讨论(0)
  • 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();
    
    0 讨论(0)
提交回复
热议问题