How to test api calls from flutter app to localhost service?
You need to use the localhost of your host machine, not the localhost of your emulator. To do that you need to use 10.0.2.2 and then your port number, so in your case make http calls to https://10.0.2.2:8080
. Internally Android reroutes calls to 10.0.2.2 to 127.0.0.1, which is the localhost ip on your dev machine.
How do you connect localhost in the Android emulator?
Some more info: https://developer.android.com/studio/run/emulator-networking.html
Doc
Okay move along, move along people, there's nothing to see here!
Updated on December 15, 2022Comments
-
Doc over 1 year
I'm trying to understand how to test http calls from my flutter app (which is running in an emulator) to my backend service, which is running in debug on my pc on
https://localhost:8080
.I get that talking to
https://localhost:8080
directly from flutter won't work because it means "emulator's localhost", so I'm talking to my pc local ip, but I gotCERTIFICATE_VERIFY_FAILED
because of course https://192.168.1.123:8080 doesn't have a signed cert.What is the correct way to handle this situation?