C# HttpClient httpClient.DefaultRequestHeaders.Authorization 标头不包含在请求中,尽管已设置

问题描述 投票:0回答:0

即使设置了授权(并且我已经验证它确实在运行时设置为正确的值),它似乎也没有正确包含在请求中。

这行不通

httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", "abc123");
var response = await httpClient.GetFromJsonAsync<ParameterAccessDto>("url/parameter_access", cancellationToken);

这确实有效

var request = new HttpRequestMessage(HttpMethod.Get, "url/parameter_access");
request.Headers.Add("Authorization", "Bearer abc123");
var response4 = await httpClient.SendAsync(request);
c# asp.net-core http http-headers httpclient
© www.soinside.com 2019 - 2024. All rights reserved.