I'm trying to set up a Xamarin Project (for the first time) in Visual Studio 2013.
I'm using a Portable Class Library for my API consumer classes, which (among other methods) contains a GET method like this:
private static async Task<string> Get(string endpoint)
{
try
{
var client = new HttpClient();
client.BaseAddress = new Uri(API_URL);
client.DefaultRequestHeaders.Accept.Add(
new MediaTypeWithQualityHeaderValue("application/json"));
var response = client.GetAsync(endpoint).Result;
string content = await response.Content.ReadAsStringAsync();
return content;
}
catch (Exception ex)
{
var t = ex.Message;
}
return null;
}
The API is set up on a publicly available server with Azure. I've tested the API from a Web-project; and it works just fine. However, when I run the iOS app through VS13 and Xamarin Build host on my Mac, I get an exception when trying to connect to the API (using the excat same method in the Portable Class Library). The exception is:
System.Net.WebExceptionStatus.ConnectFailure
with no further description. I've tested that the API is accessiable from the Mac that acts as build host, which makes me wonder, if there are some conditions for connecting to an API through an iOS app, that I don't know about.
I don't have any experience bulding Apps, and this is my first try. As I said; the API works just fine when accessed through a Web-project. What am I missing here?