HttpClient HttpClient HttpClient HttpClient Constructors

Definition

Overloads

HttpClient() HttpClient() HttpClient()

Initializes a new instance of the HttpClient class.

HttpClient(HttpMessageHandler) HttpClient(HttpMessageHandler) HttpClient(HttpMessageHandler) HttpClient(HttpMessageHandler)

Initializes a new instance of the HttpClient class with a specific handler.

HttpClient(HttpMessageHandler, Boolean) HttpClient(HttpMessageHandler, Boolean) HttpClient(HttpMessageHandler, Boolean) HttpClient(HttpMessageHandler, Boolean)

Initializes a new instance of the HttpClient class with a specific handler.

Remarks

HttpClient 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.

public class GoodController : ApiController  
{  
    // OK  
    private static readonly HttpClient HttpClient;  

    static GoodController()  
    {  
        HttpClient = new HttpClient();  
    }  
}  

HttpClient() HttpClient() HttpClient()

Initializes a new instance of the HttpClient class.

public:
 HttpClient();
public HttpClient ();
Public Sub New ()

HttpClient(HttpMessageHandler) HttpClient(HttpMessageHandler) HttpClient(HttpMessageHandler) HttpClient(HttpMessageHandler)

Initializes a new instance of the HttpClient class with a specific handler.

public:
 HttpClient(System::Net::Http::HttpMessageHandler ^ handler);
public HttpClient (System.Net.Http.HttpMessageHandler handler);
new System.Net.Http.HttpClient : System.Net.Http.HttpMessageHandler -> System.Net.Http.HttpClient
Public Sub New (handler As HttpMessageHandler)

Parameters

handler
HttpMessageHandler HttpMessageHandler HttpMessageHandler HttpMessageHandler

The HTTP handler stack to use for sending requests.

Exceptions

Remarks

handler will be disposed of by calling HttpClient.Dispose.

HttpClient(HttpMessageHandler, Boolean) HttpClient(HttpMessageHandler, Boolean) HttpClient(HttpMessageHandler, Boolean) HttpClient(HttpMessageHandler, Boolean)

Initializes a new instance of the HttpClient class with a specific handler.

public:
 HttpClient(System::Net::Http::HttpMessageHandler ^ handler, bool disposeHandler);
public HttpClient (System.Net.Http.HttpMessageHandler handler, bool disposeHandler);
new System.Net.Http.HttpClient : System.Net.Http.HttpMessageHandler * bool -> System.Net.Http.HttpClient
Public Sub New (handler As HttpMessageHandler, disposeHandler As Boolean)

Parameters

handler
HttpMessageHandler HttpMessageHandler HttpMessageHandler HttpMessageHandler

The HttpMessageHandler responsible for processing the HTTP response messages.

disposeHandler
Boolean Boolean Boolean Boolean

true if the inner handler should be disposed of by HttpClient.Dispose, false if you intend to reuse the inner handler.

Exceptions

Applies to