1.73.0 (latest) 1.69.0 1.68.0 1.60.0 1.59.0 1.55.0 1.50.0

    public class HttpClientFactory : IHttpClientFactory

The default implementation of the HTTP client factory.

## Inheritance

[object](https://learn.microsoft.com/dotnet/api/system.object) \> HttpClientFactory

## Implements

[IHttpClientFactory](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Http.IHttpClientFactory.md.txt)

## Inherited Members

[object.Equals(object)](https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object)) [object.Equals(object, object)](https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object-system-object)) [object.GetHashCode()](https://learn.microsoft.com/dotnet/api/system.object.gethashcode) [object.GetType()](https://learn.microsoft.com/dotnet/api/system.object.gettype) [object.MemberwiseClone()](https://learn.microsoft.com/dotnet/api/system.object.memberwiseclone) [object.ReferenceEquals(object, object)](https://learn.microsoft.com/dotnet/api/system.object.referenceequals) [object.ToString()](https://learn.microsoft.com/dotnet/api/system.object.tostring)

## Namespace

[Google.Apis.Http](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Http.md.txt)

## Assembly

Google.Apis.Core.dll

## Constructors

### HttpClientFactory()

    public HttpClientFactory()

Creates a new instance of [HttpClientFactory](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Http.HttpClientFactory.md.txt).

### HttpClientFactory(IWebProxy)

    protected HttpClientFactory(IWebProxy proxy)

Creates a new instance of [HttpClientFactory](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Http.HttpClientFactory.md.txt) that
will set the given proxy on HTTP clients created by this factory.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `proxy` | `IWebProxy` The proxy to set on HTTP clients created by this factory. May be null, in which case no proxy will be used. |

## Properties

### Proxy

    public IWebProxy Proxy { get; }

Gets the proxy to use when creating HTTP clients, if any.
May be null, in which case, no proxy will be set for HTTP clients
created by this factory.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `IWebProxy` |   |

## Methods

### CreateClientHandler()

    protected virtual HttpClientHandler CreateClientHandler()

Create a [HttpClientHandler](https://learn.microsoft.com/dotnet/api/system.net.http.httpclienthandler) for use when communicating with the server.
Please read the remarks closely before overriding this method.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `HttpClientHandler` | A suitable [HttpClientHandler](https://learn.microsoft.com/dotnet/api/system.net.http.httpclienthandler). |

**Remarks** When overriding this method, please observe the following:

- [AllowAutoRedirect](https://learn.microsoft.com/dotnet/api/system.net.http.httpclienthandler.allowautoredirect) and [AutomaticDecompression](https://learn.microsoft.com/dotnet/api/system.net.http.httpclienthandler.automaticdecompression) of the returned instance are configured after this method returns. Configuring these within this method will have no effect.
- [Proxy](https://learn.microsoft.com/dotnet/api/system.net.http.httpclienthandler.proxy) is set in this method to [Proxy](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Http.HttpClientFactory.md.txt#Google_Apis_Http_HttpClientFactory_Proxy) if [Proxy](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Http.HttpClientFactory.md.txt#Google_Apis_Http_HttpClientFactory_Proxy) value is not null. You may override that behaviour.
- Return a new instance of an [HttpClientHandler](https://learn.microsoft.com/dotnet/api/system.net.http.httpclienthandler) for each call to this method.
- This method may be called once, or more than once, when initializing a single client service.

<br />

### CreateHandler(CreateHttpClientArgs)

    protected virtual HttpMessageHandler CreateHandler(CreateHttpClientArgs args)

Creates a HTTP message handler. Override this method to mock a message handler.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `args` | `CreateHttpClientArgs` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `HttpMessageHandler` |   |

### CreateHttpClient(CreateHttpClientArgs)

    public ConfigurableHttpClient CreateHttpClient(CreateHttpClientArgs args)

Creates a new configurable HTTP client.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `args` | `CreateHttpClientArgs` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `ConfigurableHttpClient` |   |

### ForProxy(IWebProxy)

    public static HttpClientFactory ForProxy(IWebProxy proxy)

Creates a new instance of [HttpClientFactory](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Http.HttpClientFactory.md.txt) that
will set the given proxy on HTTP clients created by this factory.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `proxy` | `IWebProxy` The proxy to set on HTTP clients created by this factory. May be null, in which case no proxy will be used. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `HttpClientFactory` |   |

## Extension Method

[Utilities.ThrowIfNull\<T\>(T, string)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Util.Utilities.md.txt#Google_Apis_Util_Utilities_ThrowIfNull__1___0_System_String_)