我正在使用HttpClient,由于某种原因,在尝试使用Bearer令牌调用GET时,它总是给我401(未授权)响应。这是我的代码:
try
{
HttpClient httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
var response = await httpClient.GetAsync(url);
var strContent = response.Content.ReadAsStringAsync().Result;
return strContent;
}
如何使其工作,因为我一直使用邮递员放置令牌,该令牌始终有效,但由于某些原因,它在C#中不起作用