System.Net.Http.HttpRequestException "无路由到主机"在本地网络地址上?



我正试图连接到我的一个基于IOT ESP32的web服务器,该服务器来自Xamarin Android原生项目,代码如下:

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

然而,timout似乎被忽视了,无论有没有它,我都会收到

System.Net.Http.HttpRequestException:"没有到主机的路由">

  • 如何从Xamarin Android原生应用程序正确连接到本地网络中的地址
  • 是什么导致了此异常

网络一切正常,服务器几乎可以从任何其他操作系统访问,包括除Android之外的微控制器。

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

最新更新