报错:flutter: Connection refused, errno = 111, address = 127.0.0.1, port = 38870_TonyChen-9102的博客-CSDN博客

baacloud免费翻墙vpn注册使用

来源: 报错:flutter: Connection refused, errno = 111, address = 127.0.0.1, port = 38870_TonyChen-9102的博客-CSDN博客

报错:
flutter: Connection refused, errno = 111, address = 127.0.0.1, port = 38870

解决方法:
原因原来是127.0.0.1 和localhost 指向的是虚拟机的地址,并非电脑本地。

https://stackoverflow.com/questions/6760585/accessing-localhostport-from-android-emulator

所以我们只需要修改接口的127.0.0.1或localhost就行了;在Android操作系统中,将本地电脑映射为10.0.2.2;亦或使用电脑ip地址。

I am using Windows 10 as my development platform, accessing 10.0.2.2:port in my emulator is not working as expected, and the same result for other solutions in this question as well.

After several hours of digging, I found that if you add -writable-system argument to the emulator startup command, things will just work.

You have to start an emulator via command line like below:

 emulator.exe -avd <emulator_name> -writable-system

Then in your emulator, you can access your API service running on host machine, using LAN IP address and binding port:

http://192.168.1.2:<port>

Hope this helps you out.

About start emulator from command line: https://developer.android.com/studio/run/emulator-commandline.

I had the same issue when I was trying to connect to my IIS .NET Webservice from the Android emulator.

  1. install npm install -g iisexpress-proxy
  2. iisexpress-proxy 53990 to 9000 to proxy IIS express port to 9000 and access port 9000 from emulator like "http://10.0.2.2:9000"

the reason seems to be by default, IIS Express doesn’t allow connections from network https://forums.asp.net/t/2125232.aspx?Bad+Request+Invalid+Hostname+when+accessing+localhost+Web+API+or+Web+App+from+across+LAN

赞(0) 打赏
分享到: 更多 (0)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏