实测 c# .net 中 httpwebrequest 和 httpclient 性能 区别 对比
来源:互联网 发布:企业即时聊天软件 编辑:程序博客网 时间:2024/06/05 01:54
实测 c# .net 中 httpwebrequest 和 httpclient 性能区别
以下是httpclient的代码
using (var http = new HttpClient())
{//使用FormUrlEncodedContent做HttpContent
var content = new FormUrlEncodedContent(new Dictionary<string, string>()
{
{"token", steptoken},
{"id", steporderid},
{"driverId", stepdriverid}
});
s_totalwebrequest0++;
var response = await http.PostAsync("http://" + s_webapipro + "/denyOrder", content);
string res = await response.Content.ReadAsStringAsync();
s_totalwebrequest1++;
JObject obj = JObject.Parse(res);
}
以下是httpwebrequest的代码
string url = "http://" + GetWebApiPro() + "/denyOrder";
string postData = "token=" + steptoken + "&id=" + steporderid + "&driverId=" + stepdriverid;
byte[] byteArray = Encoding.UTF8.GetBytes(postData);
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(new Uri(url));
webRequest.Method = "post";
webRequest.ContentType = "application/x-www-form-urlencoded";
webRequest.ContentLength = byteArray.Length;
System.IO.Stream newStream = webRequest.GetRequestStream();
newStream.Write(byteArray, 0, byteArray.Length);
newStream.Close();
HttpWebResponse response = (HttpWebResponse)webRequest.GetResponse();
string res = new System.IO.StreamReader(response.GetResponseStream(), Encoding.GetEncoding("utf-8")).ReadToEnd();
JObject obj = JObject.Parse(res);
httpwebrequest配合 如下 配置代码,将会提升客户端的并发能力
{
- 实测 c# .net 中 httpwebrequest 和 httpclient 性能 区别 对比
- C#中HttpWebRequest性能问题
- Java.net.URLConnection和Apache HTTPClient的主要区别对比
- Java.net.URLConnection和Apache HTTPClient的主要区别对比
- .Net中 webbrowser 和 httpwebrequest 共用 cookie
- HttpClient性能对比
- 对比C#中for和foreach循环的性能
- 对比C#中for和foreach循环的性能
- 对比Oracle中truncate和delete的区别及性能
- WebRequest 和 HttpWebRequest 区别
- WebRequest 和 HttpWebRequest 区别
- WebClient和HttpWebRequest区别
- WebRequest 和 HttpWebRequest 区别
- HttpWebRequest HttpClient
- 【转】C#多线程环境下调用 HttpWebRequest 并发连接限制 HttpClient是否有默认并发数限制? 在.Net 4.0之前,一直是依靠HttpWebRequest实现Htt
- HttpClient 和HttpURLConnection 对比
- java.net 和 HttpClient的区别
- ASP.NET和PHP性能对比
- Android 使用多线程来做多文件上传Or下载
- Mac创建一个IPV6 Wifi热点
- Light Oj-1245
- 最大子序列和
- Qt::ConnectionType 解析
- 实测 c# .net 中 httpwebrequest 和 httpclient 性能 区别 对比
- Linux下MySQL的简单使用(3)
- JAVA数组
- 面对对象之封装及其好处
- CS231n课程笔记--线性分类
- 数组和指针的区别、字符数组和字符串指针区别
- Servlet中的web.xml
- Redis安装使用
- 【kmp算法next数组-串的最小循环节/循环周期】Period HDU