I wanna get Token width windows console from web API and there is my code and I occurred an error:
An error occurred while sending the request,
I use visual studio 2013, .Net FrameWork 4.5,
private static async Task<string> GetAccessToken()
{
string baseUrl = "http://my.strategy.maskan";
string _ClientId = "abc";
string _ClientSecret = "password123";
string _Scope = "api1";
using (var client = new HttpClient())
{
client.BaseAddress = new Uri(baseUrl);
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
List<KeyValuePair<string, string>> postData = new List<KeyValuePair<string, string>>();
postData.Add(new KeyValuePair<string, string>("ClientId", _ClientId));
postData.Add(new KeyValuePair<string, string>("ClientSecret", _ClientSecret));
postData.Add(new KeyValuePair<string, string>("Scope", _Scope));
FormUrlEncodedContent content = new FormUrlEncodedContent(postData);
HttpResponseMessage response = new HttpResponseMessage();
try
{
response = await client.PostAsync("IDENTITYSERVER", content);
}
catch (HttpRequestException ex)
{
Console.WriteLine(ex.Message);
}
string jsonString = await response.Content.ReadAsStringAsync();
return jsonString;
}
}
exception produce in response = await client.PostAsync("IDENTITYSERVER", content);
.
how can I fix this exception from httpClient.PostAsync.