I have a simple web-api running on localhost. This is how I call it:
using (var client = new HttpClient())
{
client.BaseAddress = new Uri("http://localhost:XXXXX/");
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
HttpResponseMessage response = client.GetAsync("api/users/").Result;
}
Now I would like to call the API from my android emulator but Im unning into trouble.
I have changed the Url to:
client.BaseAddress = new Uri("http://10.0.2.2:XXXX)
This should allow the emulator to call the localhost from what I have understood.
What happens is that the connection Times-out. If I put a BP on the line:
HttpResponseMessage response = client.GetAsync("api/users/").Result;
And hover over GetAsync
, it says Unknown member
, feels like that may have something to do with it? Any tips?