Working with HTTP

时间:2022-07-15 15:40:29

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. 天津*应急系统之GIS一张图(arcgis api for flex)讲解(四)地图导航控件模块

    config.xml文件的配置如下: <widget left="10" top="50" config="widgets/Navigation ...

  2. linux黄金命令&lbrack;积累中&rsqb;

    /usr/share/fonts/ fc-cache -v -f sudo chmod 777 ./* sudo mkfontscale sudo mkfontdir sudo fc-cache -f ...

  3. bitmap算法

    概述 所谓bitmap就是用一个bit位来标记某个元素对应的value,而key即是这个元素.由于采用bit为单位来存储数据,因此在可以大大的节省存储空间 算法思想 32位机器上,一个整形,比如int ...

  4. 跨域iframe的高度自适应

    If you cannot hear the sound of the genuine in you, you will all of your life spend your days on the ...

  5. oom&lowbar;kill&lowbar;process造成数据库挂起并出现found dead shared server

    这篇博客是上一篇博客Oracle shutdown immediate遭遇ORA-24324 ORA-24323 ORA-01089的延伸(数据库挂起hang时,才去重启的),其实这是我们海外一工厂的 ...

  6. CentOS6 搭建Git仓库

    近期上了Redmine以后,系统集成了Git的联动功能,于是萌生了搭建内网仓库的想法,特此记录一下: 1.安装Git yum -y install git 2.创建用户及密码 useradd git ...

  7. tampermonkey,采用js解析自定义脚本,实现网页列表数据采集分析

    最近一直在做数据采集的事情,目的是使用java开发一套分析指定采集规则,模拟用户动作做数据提取.因此定义了一套动作脚本,open,click,get,list,opentab,closetab...j ...

  8. 一张脑图说清 Nginx 的主流程

    一张脑图说清 Nginx 的主流程 这个脑图在 nginx-1.14.0-research 上.这是我在研究nginx的http模块的时候画的.基本上把 Nginx 主流程(特别是 HTTP 的部分) ...

  9. formbuild拖拽表单设计器

        formbuild拖拽表单设计器 表单设计器适用于OA系统.问卷调查系统.考试系统等系统,具体使用请前至官网API请点击 formbuild拖拽表单设计器     formbuild迭代几个功 ...

  10. python用zipfile模块打包文件或是目录、解压zip文件实例

    #!/usr/bin/env python # -*- coding: utf-8 -*- from zipfile import * import zipfile #解压zip文件 def unzi ...