SocketException: OS Error: Connection refused, errno = 111

I got this weird error when developing flutter app in windows. I have set my local apache as my API server. When I tested my API in Postman, everything is okay. Error appears when I tested API on my app with emulator.

Turn out, the problem is from emulator. Android emulator can’t communicate with 127.0.0.01 or localhost. The solution is just change localhost to 10.0.2.2. This IP is special alias to your host loopback interface.

You can read more about this in this docs. –> https://developer.android.com/studio/run/emulator-networking

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.