使用 HTTP REST 端点对服务器发出的请求无法正常工作 SocketException errno 64

发布于 2025-01-15 18:30:14 字数 668 浏览 3 评论 0原文

我正在尝试连接到一个端点(没有互联网 Wi-Fi),并且比做一些获取发布请求,我尝试了多个库 http dio 等..但没有积极的结果。 当我在浏览器上尝试相同的网址“http://192.168.4.1:80/getDetails”或“http://192.168.4.1/getDetails”时,它工作顺利。 而且当我尝试在应用程序上打开网址(但在线)时,它工作正常。 我怀疑该库有问题,或者我确实错过了一些要添加到我的代码中的内容,以便即使端点处于离线状态也可以向端点发出请求,有什么建议吗?

我正在真实设备 android 11 上运行该应用程序 这是我尝试过的代码:

   var httpClient = http.Client();
   var url = Uri.parse("http://192.168.4.1:80/getDetails");
   await this.httpClient.get(url, headers: <String, String>{
       'Content-Type': 'application/json; charset=UTF-8',
       'Accept': "*/*",
       'connection': 'keep-alive',
       'Accept-Encoding' : 'gzip, deflate, br',
     },);```

I am trying to connect to an endpoint (no internet Wi-Fi) and than do some get post requests, I tried multiple libraries http dio etc .. but no positive results.
and when I try the same url "http://192.168.4.1:80/getDetails" or "http://192.168.4.1/getDetails" on the browser, it works smoothly.
and also when I try an open url on the app (but online) it works fine.
I suspect there is a problem with the library or I did miss something to add to my code to can do the request to the endpoint even if it is offline, any suggestions guys.

I am running the app on real device android 11
and here is a code that I tried :

   var httpClient = http.Client();
   var url = Uri.parse("http://192.168.4.1:80/getDetails");
   await this.httpClient.get(url, headers: <String, String>{
       'Content-Type': 'application/json; charset=UTF-8',
       'Accept': "*/*",
       'connection': 'keep-alive',
       'Accept-Encoding' : 'gzip, deflate, br',
     },);```

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文