Skip to content
This repository was archived by the owner on Nov 17, 2018. It is now read-only.
This repository was archived by the owner on Nov 17, 2018. It is now read-only.

Question: How to use HttpClientHandler with IHttpClientFactory #71

@evertmulder

Description

@evertmulder

A question on how to use the IHttpClientFactory. I would like to use a named client, but with a HttpClientHandler.

This how I used to create a HttpClient

var handler = new HttpClientHandler
{
    AllowAutoRedirect = false,
    AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip
...
};
_httpClient = new HttpClient(handler);

But I would like to use the IHttpClientFactory like this:

startup.cs

services.AddHttpClient("named", c =>
{
    c.BaseAddress = new Uri("TODO");
    c.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
    c.DefaultRequestHeaders.CacheControl = new CacheControlHeaderValue
    {
        NoCache = true,
        NoStore = true,
        MaxAge = new TimeSpan(0),
        MustRevalidate = true
    };
});

How can I pass the HttpClientHandler to the named HttpClient. I was not able to find this. Any hints on how to achieve this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions