Balwant Singh

Balwant Singh

  • NA
  • 373
  • 33.4k

Unable to Consume Web Api in Xamarin

Feb 3 2020 12:11 AM
var keyValues = new List<KeyValuePair<string, string>>
{
new KeyValuePair<string, string>("username", UserName),
new KeyValuePair<string, string>("password", Password),
new KeyValuePair<string, string>("grant_type", "password")
};
var request = new HttpRequestMessage(HttpMethod.Post, "http://softstacksolutions.in/Token");
request.Content = new FormUrlEncodedContent(keyValues);
var client = new HttpClient();
var response = await client.SendAsync(request);
var jwt = await response.Content.ReadAsStringAsync();
JObject jwtynamic = JsonConvert.DeserializeObject<dynamic>(jwt);
var accessToken = jwtynamic.Value<string>("access_token");
return accessToken;
 
this code works fine on simulator but faild but app crashes while this code is called
 
why? 

Answers (1)