ioshttpflutterlocalhostdevice

Connect from ios device to localhost


I have a REST service running on my host. I can perform an HTTP request to this service from my flutter app when running on the iOS simulator using the code below:

final response = await http.get('http://localhost:8085/my/service');

However, it fails when I'm running the app on my iOS device. My device is connected via USB.

Runner[574:66922] flutter: Error SocketException: OS Error: Connection refused, errno = 61, address = localhost, port = 49575

What do I need to configure to connect to localhost from my iOS device?

I've already disabled in iTunes -> Summary "Sync with this iPad over Wi-Fi".


Solution

  • instead of localhost you can use your current ip

    to get it In the command window type: ipconfig

    Note that you must be on the same network