I have an Ionic 3 app that keeps giving me the error
"Response with Status: 404 Not found for URL:http://192.168.120.30:8100/api/login".
I’m also getting another error in the console that says
"SyntaxError: Unexpected token < in JSON position 0".
I believe the big error is the first one since it can’t even reach my API. . 192.168.120.30 is my macbooks local IP address. I have also tried without the port :8100. I am using a Macbook laptop. My backend is Laravel running on a Homestead VM with the ip 192.168.10.1. The phone and laptop are connected to the same WIFI.
I have also tried tethering my phone with my laptop and changing the IP to the phones local IP but still no luck, I keep getting the same error.
How can I resolve this?
so, a little more data…
how are you running the app? --livereload? debug mode?
on my system when I do
ionic cordova run android (or ios) -l -s -c
the app as some debugging built in that connects back to the development machine (running the ionic command) and it uses port 8100 (then 8101, then 8102…)
but none of my ‘server’ code is on my development machine…
sometimes the app and debug server are out of sync and I get a 'cannot connect to ‘…:8100’ error popup.
how do you determine the ‘server’ address to use on your ‘/api/logon’ request?
for my app, I developed a whole broadcast/response discovery method, so there is no configuration for the user. this is similar to what the home automation apps use to discover their supported devices.
the second error is that your app didn’t handle the failed connection error, and tried to parse the empty JSON response.
Hi I am running the app with the command
ionic cordova run android --device -l -c
The app works fine if I use my live server (hosted on Amazon) but not my localhost.
The server address is determined by seeing if the app is in production mode if it is than it gives the live server url otherwise my local address.
I have verified that the URL is correct
myapp.test/api/v1/login
is my local URL which works fine if I run the app through the browser just not on the phone
is the phone on wifi? if not then your local server is not addressable, unless you have some name server pointing to you network, and you have some port open in thru the network firewall…
Both my computer and phone are connected to the same wifi
and from your computer you can ping your phone? select info about your wifi connection to get the ip address…
mine comes and goes…
Yup I can ping it just fine