I am trying to use the web api\'s HttpClient to do a post to an endpoint that requires login in the form of an HTTP cookie that identifies an account (this is o
I had a similar problem and for my AspNetCore 3.1 application the other answers to this question were not working. I found that configuring a named HttpClient in my Startup.cs and using header propagation of the Cookie header worked perfectly. It also avoids all the concerns about proper disposition of your handler and client. Note if propagation of the request cookies is not what you need (sorry Op) you can set your own cookies when configuring the client factory.
IServiceCollectionservices.AddHttpClient("MyNamedClient").AddHeaderPropagation();
services.AddHeaderPropagation(options =>
{
options.Headers.Add("Cookie");
});
IApplicationBuilderbuilder.UseHeaderPropagation();
IHttpClientFactory into your controller or middleware.using var client = clientFactory.CreateClient("MyNamedClient");