aspnet/Hosting

HttpClient of TestServer.CreateClient() returns 401

vitalybibikov opened this issue · 1 comments

I'm trying to write an integration test with the help of TestServer, both CreateClient and CreateDefaultClient return 401 errors, (RedirectHandler or ClientHandler are used).

Code for CreateClient:

WebApplicationFactoryClientOptions o = new WebApplicationFactoryClientOptions();
o.BaseAddress = new Uri("http://localhost/StrategyAPI/");

var httpClient = fixture.CreateClient(o);
// httpClient.BaseAddress = new Uri("http://localhost/StrategyAPI/");

var message = new HttpRequestMessage(HttpMethod.Get, url1);
//m.Headers.Authorization =  (set Bearer)

var response1 = await httpClient.SendAsync(m);

What I'm doing wrong? Assume the handlers work somehow differently with the pipeline.

TestServer is unrelated to Authentication. More likely you're app is not correctly configured in your test environment.