HttpClient请求发送的几种用法二:
public class HttpClientHelper
{
private static readonly HttpClientHelper _instance = new HttpClientHelper();
private readonly HttpClient Client = new HttpClient();
private HttpClientHelper()
{
// Client.BaseAddress =new Uri(Options.ServerUrl);
}
public static HttpClientHelper Instance
{
get { return _instance; }
}
public string Post(string processor, Dictionary<string, string> paras)
{
var req = new HttpRequestMessage();
req.Headers.Clear();
if (processor.Contains("smsGBK.aspx"))
{
//req.Encoding = Encoding.GetEncoding("GBK");
req.Headers.Add("Content-Type", "application/x-www-form-urlencoded;charset=GB2312");
}
req.Headers.Add("ContentType", "application/x-www-form-urlencoded;charset=utf-8");
req.Method = HttpMethod.Post;
req.Content = new FormUrlEncodedContent(paras);
req.RequestUri = new Uri(Options.ServerUrl+processor);
var response = Client.SendAsync(req).Result;
try
{
response.EnsureSuccessStatusCode();
}
catch (Exception ex)
{
Trace.TraceError("Error:{0}", ex.Message);
return "";
}
return response.Content.ReadAsStringAsync().Result;
}
}
HttpClient请求发送的几种用法二:的更多相关文章
- HttpClient请求发送的几种用法:
/// <summary> /// HttpClient实现Post请求 /// </summary> static async void dooPost() { string ...
- JAVA发送HttpClient请求及接收请求结果
1.写一个HttpRequestUtils工具类,包括post请求和get请求 ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 2 ...
- JAVA发送HttpClient请求及接收请求结果过程
1.写一个HttpRequestUtils工具类,包括post请求和get请求 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 ...
- 关于HttpClient,HttpURLConnection,OkHttp的用法
1 HttpClient入门实例 1.1发送get请求 /** * HttpClient发送get请求 * @param url 请求地址 * @return * @throws IOExceptio ...
- 转 关于HttpClient,HttpURLConnection,OkHttp的用法
转自:https://www.cnblogs.com/zp-uestc/p/10371012.html 1 HttpClient入门实例 1.1发送get请求 1 2 3 4 5 6 7 8 9 10 ...
- JAVA EE 项目常用知识 之AJAX技术实现select下拉列表联动的两种用法(让你真正理解ajax)
ajax 下拉列表联动的用法. ajax的定义: AJAX 是一种用于创建快速动态网页的技术. 通过在后台与服务器进行少量数据交换,AJAX 可以使网页实现异步更新.这意味着可以在不重新加载整个网页的 ...
- C# HttpClient 请求认证、数据传输笔记
目录 一,授权认证 二,请求类型 三,数据传输 C# HttpClient 请求认证.数据传输笔记 一,授权认证 客户端请求服务器时,需要通过授权认证许可,方能获取服务器资源,目前比较常见的认证方式有 ...
- Wix 安装部署教程(十五) --CustomAction的七种用法
在WIX中,CustomAction用来在安装过程中执行自定义行为.比如注册.修改文件.触发其他可执行文件等.这一节主要是介绍一下CustomAction的7种用法. 在此之前要了解InstallEx ...
- android httpClient 支持HTTPS的2种处理方式
摘自: http://www.kankanews.com/ICkengine/archives/9634.shtml 项目中Android https或http请求地址重定向为HTTPS的地址,相信很 ...
随机推荐
- Unix/Linux环境C编程新手教程(37) shell经常使用命令演练
cat命令 cat命令能够用来查看文件内容. cat [參数] 文件名称. grep-指定文件里搜索指定字符内容. Linux的文件夹或文件. -path '字串' 查找路径名匹配所给字串的全部 ...
- 归并排序_分治算法 (白书P226)
#include<iostream> #include<cstdio> #include<algorithm> using namespace std; int a ...
- amaze ui响应式辅助
amaze ui响应式辅助 响应式辅助 就是不同的显示屏幕,或者手机的横竖屏,你可以控制栏目的显影,还是挺有帮助的 视口大小 .am-[show|hide]-[sm|md|lg][-up|-down| ...
- Onvif开发之服务端发现篇
服务端的开发相对来说比客户端稍微难一点,也就是给填充相关结构体的时候,需要一点一点的去查阅,验证各个结构中各个成员各自代表什么意思,以及对应的功能需要是那个接口实现,这是开发服务端最头疼的事情.(在开 ...
- 63.C++异常
#include <iostream> using namespace std; //异常与错误不一样,异常一般能正常工作 //错误就是程序无法正常工作,无法编译 //异常让程序在错误的输 ...
- js全局的解析与执行过程
先看下面实例的执行结果: alert(a);//undefined alert(b);//报错 alert(f);//输出f函数字符串 alert(g);//undefined var a = 1; ...
- 【Codeforces Round #428 (Div. 2) B】Game of the Rows
[Link]:http://codeforces.com/contest/839/problem/B [Description] 给你n排的如题目所示的位置; 同一排中(1,2) 算相邻; (3,4) ...
- [React] Define defaultProps and PropTypes as static methods in class component
class Toggle extends Component { static propTypes = { defaultOn: PropTypes.bool, on: PropTypes.bool, ...
- bash的启动文件
文件名称 功能描写叙述 /etc/profile 登录时自己主动运行 ~/.bash_profile,~/.bash_login,~/.profile 登录时自己主动运行 ~/.bashrc shel ...
- javascript类型系统之基本数据类型与包装类型
javascript的数据类型可以分为两种:原始类型和引用类型 原始类型也称为基本类型或简单类型,因为其占据空间固定,是简单的数据段,为了便于提升变量查询速度,将其存储在栈(stack)中(按值访问) ...