C# Http协议访问服务
来源:互联网 发布:数据库视频教程下载 编辑:程序博客网 时间:2024/05/22 02:03
public static string HttpClientService(string url, Dictionary<string, string> parameters = null) { //设置HttpClientHandler的AutomaticDecompression var handler = new HttpClientHandler() { AutomaticDecompression = DecompressionMethods.GZip }; //创建HttpClient(注意传入HttpClientHandler) using (var http = new HttpClient(handler)) { //使用FormUrlEncodedContent做HttpContent if (parameters == null) parameters = new Dictionary<string, string>() { }; var content = new FormUrlEncodedContent(parameters); //await异步等待回应 var response = http.PostAsync(url, content).Result; //确保HTTP成功状态值 //response.EnsureSuccessStatusCode(); //此时gzip已经被自动解压缩了,因为上面的AutomaticDecompression = DecompressionMethods.GZip) if (response.StatusCode == HttpStatusCode.OK) { return response.Content.ReadAsStringAsync().Result; } else { return ""; } } }
阅读全文
0 0
- C# Http协议访问服务
- HTTP访问协议封装
- HTTP协议授权访问
- HTTP协议授权访问
- HTTP 协议访问网络
- HTTP协议授权访问
- Http协议访问网络
- android访问http协议
- MFC访问http协议
- HTTP协议编程 C#
- C# 与 http 协议
- C#使用HTTP协议
- C#访问HTTP请求
- 让浏览器可以访问我们的socket服务 (http协议入门)
- 使用HTTP协议访问互联网
- Android Http协议访问网络
- 使用http协议访问网络地址
- 《HTTP协议授权访问》修订
- VS2013读取.txt文件fopen报错C4996
- 修改centos系统时间不对的问题
- Subarray Sum Equals K
- Linux 监控内存
- UVA12627ErraticExpansion
- C# Http协议访问服务
- Angular2笔记(一)--组件及组件树
- Android studio 项目构建三|编译缓存
- mysql语句统计天数,datediff函数的使用
- Javascript调试之console对象,它的一些小技巧你都知道吗?
- VMware虚拟机设置静态ip联网的问题
- 【bzoj2091】 [Poi2010]The Minima Game
- oracle.sql.TIMESTAMP cannot be cast to java.sql.Timestamp 异常的解决办法
- [Tools]Android Studio代码提示功能--Ctrl+Alt+Space(空格键)