简体   繁体   English

Flutter “连接被拒绝” (errno=111) 尝试发送 http 获取请求以从物理设备到 pc

[英]Flutter “Connection Refused” (errno=111) when trying to send an http get request to from physical device to pc

I built a flutter app which communicates with a web server that I wrote with flask.我构建了一个 flutter 应用程序,它与我用 flask 编写的 web 服务器通信。 Everything works as intended without any errors if I use a virtual device.如果我使用虚拟设备,一切都按预期工作,没有任何错误。 As soon as I try it in release mode on a physical device I get problems when it comes to the communication with the server一旦我在物理设备上以发布模式尝试它,在与服务器通信时就会遇到问题

The only thing that I changed when using a physical device is the ip.我在使用物理设备时唯一改变的是 ip。 I use 10.0.2.2 on the virtual device and my computers ip4 adress - that I get with ipconfig in windows 10 - on the physical device我在虚拟设备上使用10.0.2.2和我的计算机 ip4 地址 - 我在 windows 10 中使用 ipconfig 获得 - 在物理设备上

  • Both devices are in the same network connected to the same router两台设备都在同一个网络中,连接到同一个路由器
  • Internet Permission is enabled in the AndroidManifest for all modes (Debug, Main, Profile)在 AndroidManifest 中为所有模式(Debug、Main、Profile)启用 Internet 权限
  • I even disabled the firewall我什至禁用了防火墙

The line that causes the issue is导致问题的行是

 await http.get(url).timeout(Duration(seconds: 15), onTimeout: () {
        // Handle timeout
        // This entire thing is in a try-catch block in an async function
      });

In debug mode on the physical device when the HTTP get request is sent VSCode immediately says在物理设备上的调试模式下,当发送 HTTP 获取请求时 VSCode 立即说

Exception has occurred.
SocketException (SocketException: OS Error: Connection refused, errno = 111, address = 192.168.178.20, port = 43378)

First Question: Why Port 43378?第一个问题:为什么是端口 43378? Is that the port the HTTP request is sent to?是 HTTP 请求发送到的端口吗? Because when I run the flask app it says:因为当我运行 flask 应用程序时,它说:

Running on http://127.0.0.1:5000/

Could that be the issue?这可能是问题吗? I would have expected the exception to say the port is 5000 as declared in the URL.我本以为例外会说端口是 5000,如 URL 中所声明的那样。 Or do I have to change something with how I set up the flask app?或者我是否必须更改设置 flask 应用程序的方式? Currently it is the development server because I am still testing before I pay money and deploy目前它是开发服务器,因为我在付款和部署之前仍在测试

However I hope I didnt forget any important information.但是我希望我没有忘记任何重要信息。 Any advice on what could be wrong or how to debug here is highly aprecciated任何关于可能出错或如何在此处调试的建议都非常受欢迎

Pass an Uri object to http.get func.将 Uri object 传递给 http.get func。 Uri classes let you specify the port as Documentation https://api.dart.dev/stable/2.12.0/dart-core/Uri-class.html Uri 类允许您将端口指定为文档https://api.dart.dev/stable/2.12.0/dart-core/Uri-class.ZFC35FDC70D5FC69D2693EZ883A822C7A

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 urlopen 错误 [errno 111] 连接被拒绝 - urlopen error [errno 111] connection refused Errno111 连接被拒绝 Kivy 套接字错误 - Errno111 Connection Refused Kivy Socket Error SocketException:连接被拒绝(操作系统错误:连接被拒绝,errno = 111),地址 = localhost,端口 = 44382 - SocketException: Connection refused (OS Error: Connection refused, errno = 111), address = localhost, port = 44382 应用程序无法在 android 上运行 [连接被拒绝(操作系统错误:连接被拒绝,errno = 111)] 地址 = 本地主机,端口 = 51034 - App in not working on android[ Connection refused (OS Error: Connection refused, errno = 111) ] address = localhost, port = 51034 在Android设备上拒绝Http连接 - Http Connection Refused on Android Device 如何在不使用互联网连接的情况下将android物理应用中的http消息发送到本地服务器? - How can I send http messages from android app( physical device) to my local server without using internet connection? (颤振,Linux,VS 代码,Android 物理设备)当写入 flutter 运行 =&gt; 失去与设备的连接 - (Flutter, Linux, VS code, Android Physical device) When write flutter run => lost connection to device 未处理的异常:SocketException:操作系统错误:连接被拒绝,errno = 111,地址 = 127.0.0.1,端口 = 40712 - Unhandled Exception: SocketException: OS Error: Connection refused, errno = 111, address = 127.0.0.1, port = 40712 AndroidViewClient中的Culebra返回“ RuntimeError:错误:连接到 - Culebra in AndroidViewClient returns "RuntimeError: ERROR: Connecting to <socket… [Errno 111] Connection refused 将Android设备连接到PC时异常连接被拒绝 - Exception Connection refused while connecting Android device to PC
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM