Deepak Verma

Deepak Verma

  • 1.1k
  • 682
  • 42.3k

Web API Connection Failure In Xamarin Android

Apr 20 2018 6:34 AM
I have published my Web API on IIS and when I am consuming it in my Xamarin Android App, it is throwing error i.e., Connection Failure. I have written this code:-
 
public HotDogRepository()
{
Task.Run(() => this.LoadDataAsync(url)).Wait();
}
private async Task LoadDataAsync(string uri)
{
try
{
if (hotDogGroups != null)
{
string responseJsonString = null;
using (var httpClient = new HttpClient())
{
Task getResponse = httpClient.GetAsync(uri);
HttpResponseMessage response = await getResponse;
responseJsonString = response.Content.ReadAsStringAsync().Result;
hotDogGroups = JsonConvert.DeserializeObject >(responseJsonString);
}
}
}
catch (Exception ex)
{
throw;
}
}

Answers (2)