.net 5 中没有发生在 .net core 3.1 中的问题 Windows 身份验证未传递给 HttpClient
在 .net core 3.1 上工作的相同代码:
[HttpGet("getuser")]
public async Task<ActionResult> GetUser()
{
var handle = new HttpClientHandler
{
Credentials = CredentialCache.DefaultCredentials,
//UseDefaultCredentials = true, //=> try this too
AllowAutoRedirect = true,
};
var httpclient = new HttpClient(handle);
var res = await httpclient.GetAsync("http://service/rest/getcurrentuser"); //get 401
var result = await res.Content.ReadAsStringAsync();
return Ok(result);
}