6

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

enter image description here

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());
6
  • 1
    No it does not from android but it does from iOS. Commented Aug 26, 2018 at 17:44
  • 1
    @KirkLarkin can you make a successful request ELSEWHERE??? Commented Aug 27, 2018 at 13:45
  • 1
    It is trying to reach that server 'httpbin.org'. Commented Aug 27, 2018 at 13:56
  • 1
    How can I say it is when I am logging in then I have to send credentials with url. With that url when I do then obviously it is gonna fail as it does not accept credential properties. Commented Aug 27, 2018 at 14:35
  • your cloud api is accessible from browser directly? Commented Aug 29, 2018 at 8:45

4 Answers 4

2
+75

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.

Sign up to request clarification or add additional context in comments.

1 Comment

This happens when I am trying to interact with the cloud not local.
1

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.

4 Comments

Thank you for your answer, first I am using AWS where it accepts requests from pretty much all IPs the way I set it up. I checked config.xml file and I see this in that file <access origin="*" />. I think that means it allows everything.
I think your service is running under http not under https. This could be also because your service is not secured by SSL. If your service doesnot have SSL certificate then please add SSL certificate to your service. And i am updating my answer too.
If you are using NativeHttp then there is a option for not checking SSL certificate. try this.http.setSSLCertMode('nocheck'); this code before calling your http request. But meant to be used only for testing purposes better not to use for production.
I am currently not using SSL yet. I am using HttpClient from @angular/common/http. I am not sure about NativeHttp
1

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 :)

Comments

-1

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

5 Comments

Thanks but where can I find that property?
BTW this happens when I am trying to interact with remote url that is real production server. Any idea?
Actually just tried that but I still get the same error. I added process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"; in my app.js file in nodejs.
Well I used cor npm module though.
yeah which you have mentioned already, but i see a problem there. check if that has been configured properly

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.