Working with HTTP
A WebClient façade class for simple download/upload operations via HTTP or FTP
WebRequest and WebResponse classes for low-level control over client-side HTTP or FTP operations
HttpClient for consuming HTTP web APIs and RESTful services
1. Concurrent requests
var client = new HttpClient();
var task1 = client.GetStringAsync ("http://www.linqpad.net");
var task2 = client.GetStringAsync ("http://www.albahari.com");
Console.WriteLine (await task1);
Console.WriteLine (await task2);
2. GetAsync and response messages, do handle exception
var client = new HttpClient();
// The GetAsync method also accepts a CancellationToken.
HttpResponseMessageresponse = await client.GetAsync ("http://...");
response.EnsureSuccessStatusCode();
string html = await response.Content.ReadAsStringAsync();
3. SendAsync and request messages
var client = new HttpClient();
var request = new HttpRequestMessage (HttpMethod.Get, "http://...");
HttpResponseMessage response = await client.SendAsync (request);
response.EnsureSuccessStatusCode();
GetAsync is one of four methods corresponding to HTTP’s four verbs (the others are PostAsync, PutAsync, DeleteAsync).
The four methods are all shortcuts for calling SendAsync, the single low-level method into which everything else feeds.
随机推荐
- Ubuntu下快速安装php环境
今天蛋疼了一下,在Ubuntu下装了一下php的环境,也就是装了一下MySQL.PHP.Apache.话说还真是简单...不禁让我想起原来在windows下开发的时候撑死就是装不上,而且一个就是几个G ...
- 系统调用方式文件编程,王明学learn
系统调用方式文件编程 一.文件描述符 在Linux系统中,所有打开的文件也对应一个数字,这个数字由系统来分配,我们称之为:文件描述符. 二.函数学习 2.1打开文件 open 2.1.2 函数原形 ...
- 禁用编译器自动生成的函数(Effective C++之06)
如果想让你的类定义出来的对象是独一无二的,即对象无法被复制,或者使用赋值操作符赋给另外一个对象,那么最好的方法就是禁用拷贝构造函数和赋值操作符.下面介绍几种禁用的方法.(方法来自Effective C ...
- Codeforces Round #143 (Div. 2) E. Cactus 无向图缩环+LCA
E. Cactus A connected undirected graph is called a vertex cactus, if each vertex of this graph bel ...
- Codeforces Round #161 (Div. 2) D. Cycle in Graph(无向图中找指定长度的简单环)
题目链接:http://codeforces.com/problemset/problem/263/D 思路:一遍dfs即可,dp[u]表示当前遍历到节点u的长度,对于节点u的邻接点v,如果v没有被访 ...
- commonlisp教程以及学习笔记-01
手上有两个教程,但是感觉这个教程可能更适合自己
- 关于main函数传参数的问题
argc是命令行总的参数个数 argv[]是argc个参数,其中第0个参数是程序的全名,以后的参数 命令行后面跟的用户输入的参数,比如: int main(int ...
- Android的ADB配置环境和adb指令使用
adb的全称为Android Debug Bridge,就是起到调试桥的作用,作为一名开发者倒是常用到这个工具.借助adb工具,我们可以管理设备或手机模拟器的状态.还可以进行很多手机操作,如安装软件. ...
- express-6 请求和响应对象(1)
URL的组成部分 协议: 协议确定如何传输请求.我们主要是处理http和https.其他常见的协议还有file和ftp. 主机名: 主机名标识服务器.运行在本地计算机(localhost)和本地网络的 ...
- 疯狂java笔记(七) - Java集合之Map
Map是以键值对(key-value)的形式来存储数据的.而且Map不允许key的重复,通过Map存储key-value对时,只需要考虑key的存储就可以,key存储后value就会跟着key(完全可 ...