System.Net.Http.HttpRequestException 'No route to host' 本地网络地址?

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

我正在尝试使用以下代码从 Xamarin Android 本机项目连接到我的一个基于 IOT ESP32 的 Web 服务器:

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();
}

然而似乎超时被忽略了,不管有没有我都收到了

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

网络一切正常,几乎任何其他 OS 都可以访问服务器,包括其中的微控制器,Android 除外。

  • 找到解决方法 - 将端口从路由器重定向到服务器,并在此端口上使用外部 IP 似乎可行。