c# - Auth Request Headers not being passed in Aspire.Host.Testing scenario - Stack Overflow

admin2025-05-01  2

I recently started using Aspire and am now migrating my Integration Tests that use WebApplicationFactory to an Aspire.Host.Testing approach based on this article

With WebApplicationFactory I'm creating a HttpClient from the CreateClient of WebApplicationFactory and I'm adding the Auth Headers like this:

var client = webApplicationFactory.CreateClient();

client.DefaultRequestHeaders.Add("Authorization", BasicAuthValue);
var response = await client.GetAsync(requestUri)

I've tried to do a similar thing using DistributedApplicationTestingBuilder

var client = distributedApplication.CreateHttpClient("myWebApp");

client.DefaultRequestHeaders.Add("Authorization", BasicAuthValue);
var response = await client.GetAsync(requestUri)

However, unlike with WebApplicationFactory, the Authentication Header seems to have been removed from the request, and when it hits my WebApp, it's just not there.

转载请注明原文地址:http://www.anycun.com/QandA/1746104604a91731.html