Invalid HostName - Not able to connect IIS express from Android Emulator

Viewed 10244

I am trying to connect a WCF service hosted at my local IIS express from an Android app. Currently, I am testing this on an Emulator.

Local URL for the service is http://locahost:40000/api/Authenticate

I knew that localhost is not going to work and I used 10.0.2.2 in the code

post = new HttpPost("http://10.0.2.2:40000/api/authenticate");

but the response on client execute is an "Invalid Hostname"

I tried editing the ApplicationHost.config of IIS express and added a binding entry for 10.0.2.2 but that didn't work too

Is there anything else that I am missing ?

5 Answers

In a .NetCore project on visual studio 2022,

I edited the launchSettings.json file, under iisSettings > applicationUrl i set the url to 127.0.0.1 instead of localhost , somthing like this.

"iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": {
      "applicationUrl": "http://127.0.0.1:59109",
      "sslPort": 0
    }
  }

and in the flutter app the url is 10.0.2.2:59109

Related