Ionic 7 capactitor - ERR_CONNECTION_REFUSED (CORS)

App Info:

  • Ionic 7
  • capacitor 5
  • Run debug in Android Studio

When I start my application locally from Android Studio, which starts on localhost, I call a url http://localhost:8080.

I get the error ERR_CONNECTION_REFUSED.

Could someone tell me the steps to follow? I see a lot of information on the internet, but nothing concrete.

Thx a lot

http://localhost:8080 is an API endpoint I am assuming your app is calling? Have you checked DevTools? You can access DevTools for the Android device by going to chrome://inspect/#devices in Chrome.

Are you using an Emulator or physical device? If physical, you would need to open up port 8080 in your computer’s firewall to allow access.

Gracias por tu rapidísima respuesta.

Right, that localhost:8080 is a rh sso that I have up locally. With devtools is what I’m working with and debugging. From Android Studio I start my application, which is deployed on a physical mobile device, but I always do inspect from devtools.

Ok, so if you are on a physical device, you would have to use the FQDN or IP address of your computer instead of localhost and open up the port as I mentioned before. Also, the physical device would need to be on the same network as your computer.

For example, if your computer’s IP is 192.168.1.10 then http://192.168.1.10:8080.

Another option would be to use https://ngrok.com or https://expose.dev.

Muchas gracias, lo de la ip ya lo había probado, pero me faltaba abrir el puerto! Muchísimas gracias