I have a basic RESTful service implement in a VS 2015 project. I've just started learning Xamarin forms (in VS 2019) and I'm trying to verify that I can consume the service from the Android Emulator.
When I run the service in debug mode, I can use "http://localhost:49826/api/values/2" and get the data from the service successfully.
However, when I THEN use the same thing from my Xamarin project:
_client = new HttpClient(); _client.GetAsync("http://localhost:49826/api/values");
I get the following error:
{System.Net.WebException: Failed to connect to localhost/127.0.0.1:49826 ---> Java.Net.ConnectException: Failed to connect to localhost/127.0.0.1:49826
Following information I found here: https://learn.microsoft.com/en-us/xamarin/cross-platform/deploy-test/connect-to-local-web-services, I changed the call to:
_client.GetAsync("http://10.0.2.2:49826/api/values");
{Newtonsoft.Json.JsonReaderException: Unexpected character encountered while parsing value: <. Path '', line 0, position 0.
The client call works fine with "https://jsonplaceholder.typicode.com/posts", and the service works fine when invoked from the browser, but something is missing when I try to connect them. Any ideas?