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.

随机推荐

  1. ASP.NET 5 Beta8发布及升级经验

    (此文章同时发表在本人微信公众号"dotNET每日精华文章",欢迎右边二维码来关注.) 题记:ASP.NET 5 Beta8如期发布,这是一个重要的里程碑,因为这是ASP.NET ...

  2. linux设备驱动概述,王明学learn

    linux设备驱动学习-1 本章节主要学习有操作系统的设备驱动和无操作系统设备驱动的区别,以及对操作系统和设备驱动关系的认识. 一.设备驱动的作用 对设备驱动最通俗的解释就是“驱使硬件设备行动” .设 ...

  3. MicroService/web Service/webAPI/RPC

    [TOC] 微服务 服务拆分,利用轻量化机制(通常为HTTP源API)实现通信,复杂度可控,独立部署,技术选型灵活,容错,扩展. 康威定律的实际体现 微服务架构模式深刻影响了应用和数据库之间的关系,不 ...

  4. 10 个学习iOS开发的最佳网站(转)

    10 个学习iOS开发的最佳网站 作者 jopen 2012-09-26 08:59:56 1) Apple Learning Objective C Objective-C,通常写作ObjC和较少用 ...

  5. 智能车学习(十三)——角度控制

    一.手册代码以及图示 二.流程说明 1.角度计算函数说明 //===================================================================== ...

  6. matlab报错

    这可能说明..压根就没有这个函数

  7. Android 在地图上画矩形

    point1=map.toMapPoint(400,426); point2=map.toMapPoint(600,640); initextext = new Envelope(point1.get ...

  8. JAVA Day4

                                        循  环   所有循环的流程   声明循环变量-->判断循环条件-->执行循环操作-->更新循环变量 不断执2 ...

  9. const int *

    5.Please choose the right statement about constusage: A.const int a;//const interger B.int const a;/ ...

  10. Codeforces Round #347 (Div. 2)

    unrating的一场CF A - Complicated GCD #include <bits/stdc++.h> const int N = 1e5 + 5; char a[105], ...