I'm calling a simple REST API that I deployed on Azure app service that returns "checked" string, while the request needs a bearer token that I generate using OAuth 2.0, the request on Postman passes with no issues. But when I take the same code that postman generates on my .net 4.8 c# it fails on Http error Unauthorized (401)
var client = new HttpClient();
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", LoginService.GetAAdAccessToken()); // The token is valid at this point and I test it on Postman
Task<HttpResponseMessage> result = null;
var postCall = new Task(() => result = client.GetAsync("https://myapp.dev.com/api/check"));
postCall.RunSynchronously();
Task<string> httpResponse = null;
var postCallRes = new Task(() => httpResponse = result.Result.Content.ReadAsStringAsync());
postCallRes.RunSynchronously(); // Returns 401
Console.WriteLine(httpResponse.Result)
Any idea why the .net fails?
I tried to use different web services and to try them, SOAP & REST, both from .net 4.8 returns 401.