# Class HttpClientFactory (1.73.0)

<button class="button button-with-icon cloud-select-dropdown__button " aria-haspopup="true">Version latest</button>

- [1.73.0 (latest)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Http.HttpClientFactory)
- [1.69.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/1.69.0/Google.Apis.Http.HttpClientFactory)
- [1.68.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/1.68.0/Google.Apis.Http.HttpClientFactory)
- [1.60.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/1.60.0/Google.Apis.Http.HttpClientFactory)
- [1.59.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/1.59.0/Google.Apis.Http.HttpClientFactory)
- [1.55.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/1.55.0/Google.Apis.Http.HttpClientFactory)
- [1.50.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/1.50.0/Google.Apis.Http.HttpClientFactory)

    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)

## 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)

## 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).

### 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) that
will set the given proxy on HTTP clients created by this factory.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `proxy` | `https://learn.microsoft.com/dotnet/api/system.net.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** |
| `https://learn.microsoft.com/dotnet/api/system.net.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** |
| `https://learn.microsoft.com/dotnet/api/system.net.http.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#Google_Apis_Http_HttpClientFactory_Proxy) if [Proxy](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Http.HttpClientFactory#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` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Http.CreateHttpClientArgs` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.net.http.httpmessagehandler` |   |

### CreateHttpClient(CreateHttpClientArgs)

    public ConfigurableHttpClient CreateHttpClient(CreateHttpClientArgs args)

Creates a new configurable HTTP client.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `args` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Http.CreateHttpClientArgs` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Http.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) that
will set the given proxy on HTTP clients created by this factory.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `proxy` | `https://learn.microsoft.com/dotnet/api/system.net.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** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Http.HttpClientFactory` |   |

## Extension Method

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