I'm trying to make a get request to on premise web Api through postman and getting 401- Unauthorized error.
Is is related to security role/permission? Which security role is needed to make a call through web Api?
I'm using basic authentication.
The below code is also giving the same error.
private HttpClient getNewHttpClient(string userName,string password,string domainName, string webAPIBaseAddress)
{
HttpClient client = new HttpClient(new HttpClientHandler() { Credentials = new NetworkCredential(userName, password, domainName) });
client.BaseAddress = new Uri(webAPIBaseAddress);
client.Timeout = new TimeSpan(0, 2, 0);
return client;
}
HttpRequestMessage request = null;
try
{
request = new HttpRequestMessage(HttpMethod.Post, “api/data/v8.0/accounts”); //uri to accounts
request.Content = new StringContent(content.ToString()); //JObject of the data to be posted.
request.Content.Headers.ContentType = MediaTypeHeaderValue.Parse(“application/json”);
//Send the HttpRequest
Task<HttpResponseMessage> response = httpClient.SendAsync(requestMessage);
//Wait till the Response Execution is complete
response.Wait();
//If the response is Successfully executed then it will return the value true
if (response.Result.IsSuccessStatusCode)
{
}
}
catch (Exception err)
{
throw new Exception(err.Message);
}