✅ Add OAuth 2.0 in HttpClient Request Headers

Hi folks, I tried to request by Get using HttpClient, but in this case, I don't know how can add this "OAuth 2.0" in HttpClient to send. When I use this code I have the unauthorized 401.

var client = new HttpClient();
var request = new HttpRequestMessage
{
    Method = HttpMethod.Get,
    RequestUri = new Uri("myURL"),
    Headers =
    {
        { "Authorization", "token MyTokenCode" },
    },
};
using (var response = await client.SendAsync(request))
{
    response.EnsureSuccessStatusCode();
    var body = await response.Content.ReadAsStringAsync();
    Console.WriteLine(body);
}
image.png
Was this page helpful?