Android ERR_CONNECTION_REFUSED when running http://127.0.0.1

Hi - I am running an ionic 4 app and need to change my server url to a local ip address in order for a widget to work (intercom requires app to be run on ip address rather than localhost).

So, I added the following to my capacitor.config.json.

  "server": {
    "url": "http://127.0.0.1"
  }

This works for iOS (when I use capacitor://127.0.0.1) but for android (on the emulator), I get ERR_CONNECTION_REFUSED when loading the app.

Any help would be greatly appreciated. Have tried adding the below to my config.xml but that did not work.

<allow-navigation href="http://127.0.0.1/*"/>

Instead of setting the “url”, set the “hostname” to “127.0.0.1”

@jcesarmobile this works great! thank you!

do you know if there is any way to make these specific per platform? seems like ios needs url to be http://127.0.0.1 while android needs url to be 127.0.0.1.

I know I can change these manually on each platform, but would prefer to use something built in if possible. I tried adding the platform specific server under “ios” and “android” properties but that did not read them in at all.

Thanks for your help!

It’s not possible, but what you say sounds very weird.
By setting the hostname to “127.0.0.1” the app should load capacitor://127.0.0.1 for iOS and http://127.0.0.1 for Android.

1 Like

@jcesarmobile you’re right - works to just have the hostname set to 127.0.0.1 for both ios and android.

Thanks so much!

Thank you so much! This works for me!

Thank you so much! This works for me! After a long struggle finally got to the correct place. Really appreciate you guys.