When overriding this method, please observe the following:
AllowAutoRedirect and
AutomaticDecompression
of the returned instance are configured after this method returns.
Configuring these within this method will have no effect.
Proxy is set in this method to Proxy
if Proxy value is not null. You may override that behaviour.
Return a new instance of an HttpClientHandler for each call to this method.
This method may be called once, or more than once, when initializing a single client service.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-04 UTC."],[[["\u003cp\u003eThe \u003ccode\u003eHttpClientFactory\u003c/code\u003e class is the default implementation of the \u003ccode\u003eIHttpClientFactory\u003c/code\u003e interface for creating HTTP clients.\u003c/p\u003e\n"],["\u003cp\u003eThis class offers constructors to instantiate it, with one allowing specification of an \u003ccode\u003eIWebProxy\u003c/code\u003e instance for HTTP client configuration.\u003c/p\u003e\n"],["\u003cp\u003eIt can create an \u003ccode\u003eHttpClientHandler\u003c/code\u003e instance, where \u003ccode\u003eAllowAutoRedirect\u003c/code\u003e and \u003ccode\u003eAutomaticDecompression\u003c/code\u003e settings are applied automatically after creation, and proxy settings are taken into consideration.\u003c/p\u003e\n"],["\u003cp\u003eYou can override the \u003ccode\u003eCreateHandler\u003c/code\u003e method to provide a mock message handler, or \u003ccode\u003eCreateClientHandler\u003c/code\u003e to provide custom \u003ccode\u003eHttpClientHandler\u003c/code\u003e for different behavior.\u003c/p\u003e\n"],["\u003cp\u003eIt has a static method \u003ccode\u003eForProxy\u003c/code\u003e to conveniently create an \u003ccode\u003eHttpClientFactory\u003c/code\u003e with a specific \u003ccode\u003eIWebProxy\u003c/code\u003e already set for use.\u003c/p\u003e\n"]]],[],null,["# Class HttpClientFactory (1.69.0)\n\nVersion latestkeyboard_arrow_down\n\n- [1.69.0 (latest)](/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Http.HttpClientFactory)\n- [1.68.0](/dotnet/docs/reference/Google.Apis/1.68.0/Google.Apis.Http.HttpClientFactory)\n- [1.60.0](/dotnet/docs/reference/Google.Apis/1.60.0/Google.Apis.Http.HttpClientFactory)\n- [1.59.0](/dotnet/docs/reference/Google.Apis/1.59.0/Google.Apis.Http.HttpClientFactory)\n- [1.55.0](/dotnet/docs/reference/Google.Apis/1.55.0/Google.Apis.Http.HttpClientFactory)\n- [1.50.0](/dotnet/docs/reference/Google.Apis/1.50.0/Google.Apis.Http.HttpClientFactory) \n\n public class HttpClientFactory : IHttpClientFactory\n\nThe default implementation of the HTTP client factory. \n\nInheritance\n-----------\n\n[object](https://learn.microsoft.com/dotnet/api/system.object) \\\u003e HttpClientFactory \n\nImplements\n----------\n\n[IHttpClientFactory](/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Http.IHttpClientFactory) \n\nInherited Members\n-----------------\n\n[object.Equals(object)](https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object)) \n[object.Equals(object, object)](https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object-system-object)) \n[object.GetHashCode()](https://learn.microsoft.com/dotnet/api/system.object.gethashcode) \n[object.GetType()](https://learn.microsoft.com/dotnet/api/system.object.gettype) \n[object.MemberwiseClone()](https://learn.microsoft.com/dotnet/api/system.object.memberwiseclone) \n[object.ReferenceEquals(object, object)](https://learn.microsoft.com/dotnet/api/system.object.referenceequals) \n[object.ToString()](https://learn.microsoft.com/dotnet/api/system.object.tostring)\n\nNamespace\n---------\n\n[Google.Apis.Http](/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Http)\n\nAssembly\n--------\n\nGoogle.Apis.Core.dll\n\nConstructors\n------------\n\n### HttpClientFactory()\n\n public HttpClientFactory()\n\nCreates a new instance of [HttpClientFactory](/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Http.HttpClientFactory).\n\n### HttpClientFactory(IWebProxy)\n\n protected HttpClientFactory(IWebProxy proxy)\n\nCreates a new instance of [HttpClientFactory](/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Http.HttpClientFactory) that\nwill set the given proxy on HTTP clients created by this factory.\n\nProperties\n----------\n\n### Proxy\n\n public IWebProxy Proxy { get; }\n\nGets the proxy to use when creating HTTP clients, if any.\nMay be null, in which case, no proxy will be set for HTTP clients\ncreated by this factory.\n\nMethods\n-------\n\n### CreateClientHandler()\n\n protected virtual HttpClientHandler CreateClientHandler()\n\nCreate a [HttpClientHandler](https://learn.microsoft.com/dotnet/api/system.net.http.httpclienthandler) for use when communicating with the server.\nPlease read the remarks closely before overriding this method.\n\n**Remarks** \nWhen overriding this method, please observe the following:\n\n- [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.\n- [Proxy](https://learn.microsoft.com/dotnet/api/system.net.http.httpclienthandler.proxy) is set in this method to [Proxy](/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Http.HttpClientFactory#Google_Apis_Http_HttpClientFactory_Proxy) if [Proxy](/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Http.HttpClientFactory#Google_Apis_Http_HttpClientFactory_Proxy) value is not null. You may override that behaviour.\n- Return a new instance of an [HttpClientHandler](https://learn.microsoft.com/dotnet/api/system.net.http.httpclienthandler) for each call to this method.\n- This method may be called once, or more than once, when initializing a single client service.\n\n\u003cbr /\u003e\n\n### CreateHandler(CreateHttpClientArgs)\n\n protected virtual HttpMessageHandler CreateHandler(CreateHttpClientArgs args)\n\nCreates a HTTP message handler. Override this method to mock a message handler.\n\n### CreateHttpClient(CreateHttpClientArgs)\n\n public ConfigurableHttpClient CreateHttpClient(CreateHttpClientArgs args)\n\nCreates a new configurable HTTP client.\n\n### ForProxy(IWebProxy)\n\n public static HttpClientFactory ForProxy(IWebProxy proxy)\n\nCreates a new instance of [HttpClientFactory](/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Http.HttpClientFactory) that\nwill set the given proxy on HTTP clients created by this factory.\n\nExtension Method\n----------------\n\n[Utilities.ThrowIfNull\\\u003cT\\\u003e(T, string)](/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Util.Utilities#Google_Apis_Util_Utilities_ThrowIfNull__1___0_System_String_)"]]