This article says that we should use a static HttpClient
in order to reuse sockets.
But the first comment there says that there is a DNS changes recognition issue, and the solution is in another article here:
The second article suggested :
var client = new HttpClient();
client.DefaultRequestHeaders.ConnectionClose = true;
Which controls the KeepAlive
header.
But suffers from preventing you to take advantage of benefits of re-using a socket
Another solution was :
var sp = ServicePointManager.FindServicePoint(new Uri("http://foo.bar/baz/123?a=ab"));
sp.ConnectionLeaseTimeout = 60*1000; // 1 minute
BUT:
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.
Question:
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
- Should I still use the
static HttpClient
approach ? or should Inew HttpClient
each time I want to make a call? Or - Should I create static/not staticnew HttpClient
for eachscheme://basedns
?
He showed the problem but his Conclusion doesn't show the whole right final solution.
Please notice - I'm asking about .net framework. not .net Core.