即使设置了授权(并且我已经验证它确实在运行时设置为正确的值),它似乎也没有正确包含在请求中。
这行不通
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);