Hi, I am trying to consume the dynamics 365 online web api call through the .net application, here is the sample code, but it says unauthorized. Please help
HttpResponseMessage response = new HttpResponseMessage();
string requestUrl = string.Empty;
applicationModel result = null;
var httpClientHandler = new HttpClientHandler()
{
Credentials = new NetworkCredential(_config.GetValue("OnlineServiceSettings:UserName"),
_config.GetValue("OnlineServiceSettings:Password"), _config.GetValue("OnlineServiceSettings:Domain"))
};
HttpClient _httpClient = new HttpClient(httpClientHandler);
requestUrl = $"https://webensight.api.crm3.dynamics.com/api/data/v9.1/accounts";
response = await _httpClient.GetAsync(requestUrl, HttpCompletionOption.ResponseHeadersRead).ConfigureAwait(false);
if (response.StatusCode == HttpStatusCode.OK)
{
//string result = response.Content.ReadAsStringAsync().Result;
result = JsonConvert.DeserializeObject(response.Content.ReadAsStringAsync().Result);
return result;
}