如何下载的MetroStyle应用程序(WinRT的)和C#网页 [英] How to download a webpage in MetroStyle app (WinRT) and C#

查看:159
本文介绍了如何下载的MetroStyle应用程序(WinRT的)和C#网页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建一个MetroStyle应用程序,我想用一个网站的API是基于HTTP GET方法。比如登录我应该下载这个URL返回的XML:

I'm creating a MetroStyle app and I want to use a website API that is based on the HTTP Get methods. For instance to login I should download the XML returned by this URL:

websitehost.com/api/login.php?u=username&p=password

现在的问题是,新的MetroStyle的应用程序不会让我使用了许多我已经使用了多年在.NET中的方法,所以我怎么能下载返回的XML文档,解析它?

The problem is that the new MetroStyle apps won't let me to use many of the methods I've been using for years in .Net so how can I download the returned XML document and parse it?

推荐答案

您可能会寻找这样的:

    public async Task<string> DownloadPageStringAsync(string url)
    {
        HttpClientHandler handler = new HttpClientHandler()
        { UseDefaultCredentials = true, AllowAutoRedirect = true };

        HttpClient client = new HttpClient(handler);
        HttpResponseMessage response = await client.GetAsync(url);
        response.EnsureSuccessStatusCode();
        return await response.Content.ReadAsStringAsync();
    }

这篇关于如何下载的MetroStyle应用程序(WinRT的)和C#网页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆