Search code examples
xamarinxamarin.android

System.Net.Http.HttpRequestException 'No route to host' on local network address?


I am trying to connect to one of mine IOT ESP32 based web server from Xamarin Android native based project with the following code:

client = new HttpClient();
                
Uri uri = new Uri( "http://192.168.0.5/sensors" );
client.Timeout = TimeSpan.FromSeconds(10);
HttpResponseMessage response = client.GetAsync( uri ).GetAwaiter().GetResult();
if( response.IsSuccessStatusCode )
{
    string content = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();
}

Yet seems like the timout is ignored, and with or without it I am receiving

System.Net.Http.HttpRequestException: 'No route to host'

  • How to properly connect from Xamarin Android native app to an address inside my local network ?
  • What is causing this exception ?

Solution

  • The network is all fine, and the server is reachable from practically any other OS, including microcontrollers within it except Android.

    • Found workaround - redirecting port from the router to the server, and using external IP on this port seems like working.