Xamarin Forms App Calling Web API
-
I'm learning Xamaring Forms. I want to test connecting to a Web API. I have a an Asp.Net Framework Web API running and I can connect to to it. However, in my Xamarin Forms page, when I call it, the call to GetAsync never returns:
public class MainPageViewModel : _ViewModelBase
{
private string url = "https://localhost:44340/api/Test/GetAll";
public List Items { get; set; }
public MainPageViewModel()
{
GetData();
}
private async Task GetData()
{
try
{
HttpClient client = new HttpClient();
HttpResponseMessage response = await client.GetAsync(url); // <====== NEVER RETURNSif (response.IsSuccessStatusCode) { string content = await response.Content.ReadAsStringAsync(); Items = JsonConvert.DeserializeObject\>(content); } } catch (Exception e) { throw; } }
}
I can paste the URL into a browser and see the JSON results. If the WebAPI is NOT running the GetAsync throws. Anyone have any thoughts on this?
If it's not broken, fix it until it is. Everything makes sense in someone's mind. Ya can't fix stupid.