diff --git a/xml/System.Net.Http/HttpClient.xml b/xml/System.Net.Http/HttpClient.xml index 228db3c2597..82a63185441 100644 --- a/xml/System.Net.Http/HttpClient.xml +++ b/xml/System.Net.Http/HttpClient.xml @@ -28,6 +28,14 @@ [!WARNING] + > - is intended to be instantiated once and re-used throughout the life of an application. Instantiating an class for every request will exhaust the number of sockets available under heavy loads and result in a . However, having long-lived instances can lead to stale DNS usage and non-functional connections. Use one of the following options to avoid these problems: +> +> - Use static instances, which are recycled on a regular basis. +> - Use to create the . +> - On .NET Core and .NET 5.0 and later, use static instances and set . + The class instance acts as a session to send HTTP requests. An instance is a collection of settings applied to all requests executed by that instance. In addition, every instance uses its own connection pool, isolating its requests from requests executed by other instances. The also acts as a base class for more specific HTTP clients. An example would be a FacebookHttpClient providing additional methods specific to a Facebook web service (a GetFriends method, for instance). Derived classes should not override the virtual methods on the class. Instead, use a constructor overload that accepts to configure any pre- or post-request processing instead. @@ -56,7 +64,7 @@ 9. - is intended to be instantiated once and re-used throughout the life of an application. Instantiating an HttpClient class for every request will exhaust the number of sockets available under heavy loads. This will result in SocketException errors. Below is an example using HttpClient correctly. +The following code snippet shows how to use : ```csharp public class GoodController : ApiController @@ -2152,4 +2160,4 @@ public class GoodController : ApiController - \ No newline at end of file +