aspnet / Hosting

[Archived] Code for hosting and starting up an ASP.NET Core application. Project moved to https://github.com/aspnet/Extensions and https://github.com/aspnet/AspNetCore
Apache License 2.0
552 stars 312 forks source link

HttpClient of TestServer.CreateClient() returns 401 #1540

Closed vitalybibikov closed 5 years ago

vitalybibikov commented 6 years ago

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.

Tratcher commented 6 years ago

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