Home > Enterprise >  Flutter physical iOS device unable to make api request to my local asp.net server
Flutter physical iOS device unable to make api request to my local asp.net server

Time:12-24

When I debug my app from a physical iOS device and try to make a request to my local server, I get this error that I don't get on the iOS simulator:

SocketException (SocketException: OS Error: Connection refused, errno = 61, address = 192.168.1.186, port = 56740)

Is that port supposed to be my server port? That is 5001.

I can see in the dart dev tools debugger that this request is sent:

GET https://192.168.1.186:5001/fashionitems/search?searchTerm=Fa&currentPage=1&pageSize=10

That's the correct URL and works from the iOS simulator, so it looks like it is sending the correct request.

I'm using asp.NET 6 for the server.

I feel like the issue is my server because the google maps API requests are working from the physical device. What part of an asp.NET 6 app would I look at when it works on a simulator but not a physical device?

Anything I can look at to figure out this issue?

EDIT: In Flutter, I've seen we should use the ip address instead of 'localhost' if testing on physical devices. So I did that. Interestingly the ip address does not work for the iOS simulator though, only 'localhost' does. I did not think that was supposed to be the case.

Wifi is starlink although don't think that would make a difference.. I can't test with mobile data hotspot.

server connection string is:

  "ConnectionStrings": {
    "DefaultConnection": "Server=localhost;Port=5432;Database=vepo_dev_db;User Id=postgres;Password=password;Include Error Detail=true"
  },

on asp.net app:

launchSettings.json

{
  "$schema": "http://json.schemastore.org/launchsettings.json",
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": {
      "applicationUrl": "http://localhost:53210",
      "sslPort": 44301
    }
  },
  "profiles": {
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "launchUrl": "swagger",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "Vepo": {
      "commandName": "Project",
      "dotnetRunMessages": "true",
      "launchBrowser": true,
      "launchUrl": "GroceryItems",
      "applicationUrl": "https://localhost:5001;http://localhost:5000",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    }
  }
}

CodePudding user response:

change

"applicationUrl": "https://localhost:5001;http://localhost:5000",

to

"applicationUrl": "https://0.0.0.0:5001;http://localhost:5000",
  • Related