原文:UWP-HttpClient

基本格式:

                HttpClient client = new HttpClient();
Uri uri = new Uri(url); HttpResponseMessage response = await client.GetAsync(uri);
response.EnsureSuccessStatusCode(); string str = await response.Content.ReadAsStringAsync();

若得到Json数据:

  可以通过以下方法方便的转换到类中:

       var jsonMessage = await response.Content.ReadAsStringAsync();

            var serializer = new DataContractJsonSerializer(typeof(JsonClass));//在json2csharp中转换过来的类
var ms = new MemoryStream(Encoding.UTF8.GetBytes(jsonMessage)); var result = (JsonClass)serializer.ReadObject(ms);

若得到Xml数据:

  可以通过遍历节点将数据一个个手动存放到类中:

string xml = await response.Content.ReadAsStringAsync();
if (xml != null)
{
List<CNBlog> list_blogs = new List<CNBlog>();
CNBlog cnblog;
XmlDocument doc = new XmlDocument();
doc.LoadXml(xml);
XmlNode feed = doc.ChildNodes[1];
foreach (XmlNode node in feed.ChildNodes)
{
if (node.Name.Equals("entry"))
{
cnblog = new CNBlog();
foreach (XmlNode node2 in node.ChildNodes)
{
if (node2.Name.Equals("id"))
{
cnblog.ID = node2.InnerText;
}
if (node2.Name.Equals("title"))
{
cnblog.Title = node2.InnerText;
}
if (node2.Name.Equals("summary"))
{
cnblog.Summary = node2.InnerText + "...";
}
}
list_blogs.Add(cnblog);
}
}
}

  XML的数据如下:

  <?xml version="1.0" encoding="utf-8" ?>
- <feed xmlns="http://www.w3.org/2005/Atom">
<title type="text">博客园</title>
<id>uuid:09b99565-46b8-4767-ad8d-ea0283b7b1ac;id=41476</id>
<updated>2016-05-22T03:01:05Z</updated>
<link href="http://www.cnblogs.com/" />
- <entry>//一段的入口
<id>5516348</id>
<title type="text">教你如何剖析源码</title>
<summary type="text">有近千行代码。看着都崩溃了。。。</summary>
<published>2016-05-22T11:00:00+08:00</published>
<updated>2016-05-22T03:01:05Z</updated>
- <author>
<name>狼行博客园</name>
<uri>http://www.cnblogs.com/lang5230/</uri>
<avatar>http://pic.cnblogs.com/face/835234/20151119122152.png</avatar>
</author>
<link rel="alternate" href="http://www.cnblogs.com/lang5230/p/5516348.html" />
<blogapp>lang5230</blogapp>
<diggs>0</diggs>
<views>1</views>
<comments>0</comments>
</entry>

UWP-HttpClient的更多相关文章

  1. win10 uwp httpClient 登陆CSDN

    本文告诉大家如何模拟登陆csdn,这个方法可以用于模拟登陆其他网站. HttpClient 使用 Cookie 我们可以使用下面代码让 HttpClient 使用 Cookie ,有了这个才可以保存登 ...

  2. dotnet 从入门到放弃的 500 篇文章合集

    本文是记录我从入门到放弃写的博客 博客包括 C#.WPF.UWP.dotnet core .git 和 VisualStudio 和一些算法,所有博客使用 docx 保存 下载:dotnet 从入门到 ...

  3. 2018-2-13-win10-uwp-HttpClient-post错误

    title author date CreateTime categories win10 uwp HttpClient post错误 lindexi 2018-2-13 17:23:3 +0800 ...

  4. 2018-8-10-win10-uwp-httpClient-登陆CSDN

    title author date CreateTime categories win10 uwp httpClient 登陆CSDN lindexi 2018-08-10 19:16:53 +080 ...

  5. 2018-8-10-dotnet-从入门到放弃的-500-篇文章合集

    title author date CreateTime categories dotnet 从入门到放弃的 500 篇文章合集 lindexi 2018-08-10 19:16:52 +0800 2 ...

  6. 揭秘Windows10 UWP中的httpclient接口[2]

    阅读目录: 概述 如何选择 System.Net.Http Windows.Web.Http HTTP的常用功能 修改http头部 设置超时 使用身份验证凭据 使用客户端证书 cookie处理 概述 ...

  7. UWP 使用HttpClient获取网页数据

    我的App自然灾害中,为了展示地震的各种信息,就需要从网页上获取地震源数据. 如图所示,我们需要展示 地震等级.地震发生时间.经纬度.震源深度.地震位置等信息. 那么,假设给了一个地震的源,中国地震台 ...

  8. 详解 UWP (通用 Windows 平台) 中的两种 HttpClient API

    UWP (通用 Windows 平台) 应用开发者在构建通过 HTTP 与 Web 服务或服务器断点交互的应用时,有多种 API 可以选择.要在一个托管 UWP 应用中实现 HTTP 客户端角色,最常 ...

  9. UWP 使用Windows.Web.Http命名空间下的HttpClient使用post方法,上传图片服务器

    1.从相册里面选取图片 /// <summary> /// 1.1 从相册里面选取图片 /// </summary> /// <param name="send ...

  10. UWP 律师查询 MVVM

    APP简介 律师查询是基于聚合数据的律师查询接口做的,这个接口目前处于停用状态,但是,由于我是之前申请的,所以,还可以用,应该是无法再申请了. 效果图 开发 一.HttpHelper 既然是请求接口的 ...

随机推荐

  1. 【hdu 2177】取(2堆)石子游戏

    Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s) ...

  2. Redis的常识

    https://github.com/springside/springside4/wiki/redis 1. Overview 1.1 资料 <The Little Redis Book> ...

  3. Linux中mv重命名作用及打包war压缩文件及分配权限

    1.Linux中的重命名文件使用mv命令 touch a.txt 新建一个文件 mv a.txt b.txt 重命名文件为b.txt mkdir abc 新建一个目录 mv abc abd 重命名文件 ...

  4. [GeekBand] C++ 内存分布—— new和delete重载的实现及分析

    本文参考文献:GeekBand课堂内容,授课老师:侯捷 :深度探索C++对象模型(侯捷译) :网络资料: http://www.leavesite.com/geekband-cpp-5.html ht ...

  5. 三种方法解决 Failed to start LSB: Bring up/down networking 问题

    感谢朋友支持本博客.欢迎共同探讨交流.因为能力和时间有限,错误之处在所难免.欢迎指正! 假设转载.请保留作者信息. 博客地址:http://blog.csdn.net/qq_21398167 原博文地 ...

  6. reflect(反射)了解一点点

    A a = new A() 这个代码在程序编译阶段,会自己主动定位到A类上,而且新建一个A的实例. 可是假设我们希望程序在执行时.动态的创建一个A的实例.此时程序仅仅知道要从名字叫A的类中创建一个实例 ...

  7. error: openssl/md5.h: No such file or directory

    出现:error: openssl/md5.h: No such file or directory 原因是openssl-devel没有安装,运行: yum install libssl-dev 就 ...

  8. Android SDK location should not contain whitespace, as this cause problems with NDK tools

    解决方案一: The easiest solution is to move the SDK somewhere else, where there is no space or other whit ...

  9. 用Ruby实现的论坛灌水工具:CC98 Post Machine

    介绍 ZJU 的校网论坛 CC98 比较活跃.论坛只对校内网开放,而且账号跟学生绑定,每个学生注册的账号数量有限.『十大』是 CC98 的经典页面:基于关注的人数(回帖的用户数而不是回帖的数量)用算法 ...

  10. 编译和使用jasper库的一个注意事项

    作者:朱金灿 来源:http://blog.csdn.net/clever101 由于jasper库是一个跨平台库,而Windows的VC编译器和Linux的GCC编译器的头文件并不完全一致(可能因为 ...