Reputation: 1162
I have an ionic app that when I run that on iOS then it works perfectly fine but when I run that on Android I get this error
Http failure response for (unknown url): 0 Unknown Error
Any reason I am getting this one? I have allowed CORS on server side as it is working on iOS devices.
Any help?
EDIT
This is what I have in my app.js file
const cors = require('cors');
And then I simply use it with default options.
app.use(cors());
Upvotes: 6
Views: 3506
Reputation: 272
We had experienced the same Error several times in our App. In our case it was a problem with the headers of the request and also a CORS problem on the serverside.
Are you able to reproduce this error in the browser if you emulate a android device? Then you could compare them with the headers of the iOS request.
Or you can try to log the incoming requests on the server-side to see if the requests reach the server and what headers are set.
Hope my ideas help :)
Upvotes: 1
Reputation: 905
First you dont need CORS to call API from your android device.
Second probably your server is not accepting your request. If you are using Cloud then your server must accept request from any IP. There must be a option for allow IP address, place there from 0.0.0.1 to 254.254.254.254 so that each and every user can call your API.
Third you need to allow origin from your config.xml
and also in header for CROS request. Check your API header and config
file.
And fourth If your service is running under http then it will also could be the problem. Secure your service by adding SSL certificate. This could fix your problem.
Upvotes: 1
Reputation: 222722
The solution is to add NODE_TLS_REJECT_UNAUTHORIZED=0
to your environment to disable the SSL verification in Node.js.
Note :
You should only set this in development, Don't do this in production
EDIT
In that case it indicates that CORS has not been properly setup on your server. Go through the issue here
Upvotes: -1
Reputation: 10235
If you are using localhost
, change it to the IP address of the localhost. Android
doesn't seems to support it where iOS
do.
Try actual host name in case it didn't work too.
Upvotes: 2