HttpClient和套接字耗尽-澄清吗? [英] HttpClient and socket exhaustion - clarification?

查看:106
本文介绍了HttpClient和套接字耗尽-澄清吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

本文 表示我们应该使用静态 HttpClient 以便重用套接字.

但是那里的第一条评论说存在DNS更改识别问题,解决方案在另一篇文章

But the first comment there says that there is a DNS changes recognition issue, and the solution is in another article here:

第二篇文章建议:

var client = new HttpClient();
client.DefaultRequestHeaders.ConnectionClose = true; 

哪个控件控制 KeepAlive 标头.但是会妨碍您利用重新使用套接字的好处

Which controls the KeepAlive header. But suffers from preventing you to take advantage of benefits of re-using a socket

另一个解决方案是:

var sp = ServicePointManager.FindServicePoint(new Uri("http://foo.bar/baz/123?a=ab"));
sp.ConnectionLeaseTimeout = 60*1000; // 1 minute

但是:

他没有说我们每次要发出请求时是否应该使用 new Httpclient ,还是应该仍然使用静态请求.

He didn't say whether should we use new Httpclient each time we want to make a request, or should we still use the static one.

问题:

说我要使用此解决方案:

Say I want to use this solution :

var sp = ServicePointManager.FindServicePoint(new Uri("http://foo.bar/baz/123?a=ab"));
sp.ConnectionLeaseTimeout = 60*1000; // 1 minute 

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆