Closed jwilkeson closed 1 year ago
I ended up fixing this, part of the problem was that because the app was launched with https, I couldn't access localhost as it was only capable of http so I installed an ssl cert and also used https://10.0.0.2
which on android emulators directs to the hosts doc root and it seems to be working now.
Just for context, Android emulators are full virtual machines with their own virtual network stack. Therefore localhost
will resolve to itself, the virtual machine, rather than the host machine. Physical devices will work the same way.
Additionally, if you're using schemes via <preference name="hostname" value="localhost" />
then the webview will (in simple terms) intercept http://localhost
or (https://localhost
if scheme
is set to https
) and remap urls to load from the local file system. It somewhat behaves like a virtual webserver that only the process itself can have access to.
That is why changing the url to use a private IP https://10.0.0.2
works. On mac/linux, you can look up your private ip using the ifconfig
command, most home networks uses a 192.168.x.x
ip scheme
Bug Report
Problem
No matter what I do, I get
net::ERR_CONNECTION_REFUSED
when making afetch()
call to a domain running onhttp://localhost:8002
What is expected to happen?
fetch('http://localhost:8002') .then(response => { return response.text() }).then(response => alert(response));
should alerthello world
What does actually happen?
I get an error
Failed to load resource: net::ERR_CONNECTION_REFUSED
Information
Command or Code
index.html
index.js
config.xml
Environment, Platform, Device
package.json
cordova run android
It returnsCONNECTION_REFUSED
forcordova_plugins.js
as well, it's not really the issue as far as I know but I feel like it might give insight.Version information
cordova -version
: 11.0.0cordova-plugin-whitelist
but as I understand it's been integratedChecklist
Things I've Tried
cordova prepare android
followed bycordova build android
followed bycordova run android
<preference name="hostname" value="localhost" /> <preference name="AndroidInsecureFileModeEnabled" value="true" />
cordova-android
versions