I've been reading about how to use HttpClient
in .NET Framework.
The two main points I gathered was that HttpClient
should be a singleton, and ServicePointManager.FindServicePoint()
needs to be called in case of DNS changes.
But what do you pass to FindServicePoint()
?
In this example, it passes the full URL:
var sp = ServicePointManager.FindServicePoint(new Uri("http://foo.bar/baz/123?a=ab"));
sp.ConnectionLeaseTimeout = 60*1000; // 1 minute
However, in this example, it only passes in the base URL:
Uri baseUri = new Uri("https://someresource.com");
...
ServicePointManager.FindServicePoint(baseUri).ConnectionLeaseTimeout = 60 * 1000;
The HttpClient
instance will be making requests to different resources all from the same host (eg. domain.com/resourceA
and domain.com/resourceB
).
I've read this answer, however unfortunately I can't use it as we don't have DI set up in our project.