I'm trying to setting my Jwt token in C# code.
[HttpPost]
public IActionResult TestPOST ()
{
var token = "myExampleJwtTokenNormallyIGrabItFromOtherFunction";
var client = new HttpClient();
client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", token);
return Ok();
}
This method just return Ok(), but Authorization is not setting. And I still have 401 http error. I cannot figured out what can be wrong here. I read that should I use
client.DefaultRequestHeaders.TryAddWithoutValidation("Authorization", "Bearer " + token);
but it still does not work. How should I set header? Have anyone any idea?