Http request gives net::ERR_CONNECTION_REFUSED when running on device


NOTE: For additional information, please visit the relevant post on StackOverflow

App needs to talk to remote API server via https as well as load Google Maps javascript library. So far I’ve been testing and debugging using ionic serve. I have proxies configured in ‘ionic.config.json’ and everything works as expected. Things fall apart when running app on physical device. I repeatedly get net::ERR_CONNECTION_REFUSED for any type of request. The only time it seems to event slightly work is when I use ionic run android -l --device. But when doing so, it’s basically using the proxy server along with the configurations set. However, in this case I’m still getting the CONNECTION_REFUSED error when trying to establish socket connections. According to the Handling CORS Issues in Ionic article, I should be able to just use the API urls directly without having to set up any other configurations, but for the life of me, I can’t seem to get it to work. I’ve tried numerous solutions that have been posted on this forum as well as other sites but nothing seems to be working. The following is the output from ionic info:

Cordova CLI: 6.4.0
Ionic Framework Version: 2.0.0-rc.4
Ionic CLI Version: 2.1.18
Ionic App Lib Version: 2.1.9
Ionic App Scripts Version: 0.0.47
ios-deploy version: 1.9.0
ios-sim version: 5.0.10
OS: macOS Sierra
Node Version: v7.3.0
Xcode version: Xcode 8.2.1 Build version 8C1002