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.
随机推荐
- PL/SQL Developer 9.x 注册码
记下来,以备以后使用,好笔头,哈哈哈 Product Code:46jw8l8ymfmp2twwbuur8j9gv978m2q2du serial Number:307254 password:xs3 ...
- 第十八篇:在SOUI中实现PreTranslateMessage
在MFC中,通常可以通过重载CWnd::PreTranslateMessage这样一个虚函数来实现对一些窗口消息的预处理.多用于tooltip的显示控制. 在SOUI中也实现了类似的机制. 要在SOU ...
- [荐]jquery插件开发入门
http://www.cnblogs.com/Wayou/p/jquery_plugin_tutorial.html $.fn.myPlugin = function() { //在这里面,this指 ...
- 用 C# 实现一个简单的 Rest Service 供外部调用
用 C# 实现一个简单的 Restful Service 供外部调用,大体总结为4点: The service contract (the methods it offers). How do yo ...
- update comboBox
/// <summary> /// AutoCompleteComboBox /// </summary> public class AutoCompleteComboBox ...
- 使用python做科学计算
这里总结一个guide,主要针对刚开始做数据挖掘和数据分析的同学 说道统计分析工具你一定想到像excel,spss,sas,matlab以及R语言.R语言是这里面比较火的,它的强项是强大的绘图功能以及 ...
- 对于c语言int类型和float,以及double类型表示范围的计算
首先说一下我原来错误的认识 int是32个bit, 如果我们把第一位理解为符号位,那么很显然int的范围是-(2^31-1)~2^31-1 但是实际上我们都知道int的最小值是-2^31次.. 为什么 ...
- 在Android上用AChartEngine轻松绘制图表
本文由 伯乐在线 - LeonHover 翻译.未经许可,禁止转载!英文出处:jaxenter.欢迎加入翻译组. Android发布不久的2008年底,开发者们已经开始寻找制表.制图.绘图的工具库.当 ...
- python限定类属性的类属性:__slots__
__slots__ 由于Python是动态语言,任何实例在运行期都可以动态地添加属性. 如果要限制添加的属性,例如,Student类只允许添加 name.gender和score 这3个属性,就可以利 ...
- POJ 1159 回文串-LCS
题目链接:http://poj.org/problem?id=1159 题意:给定一个长度为N的字符串.问你最少要添加多少个字符才能使它变成回文串. 思路:最少要添加的字符个数=原串长度-原串最长回文 ...