REST Api call not working on android device


#1

Hi.

I’m working on an android app and I’m making api calls to a REST Api. In my chrome browser, the api call works perfectly and I can see the result in my console log. But on my device, I keep getting a 404 error.

I created a service for the api call, and I have created proxies because of CORS issues. Everything works fine on the device. Before running app on the device, I changed the url from the localhost proxy to the actual url of the rest api, this still gives me an error. Any help will be appreciated. Thank you.


#2

Sounds like you need this.


#3

Thanks. But please, how do I use it.
There are so many options but Im thinking its between the last two

Thanks again


#4

you should just need to add and thats all.


#5

I have the same problem … Any solution


#6

I just did this today after dreading it for a couple of weeks.

Here’s what I did to get it going (not pretending it’s the most secure):

  1. Add plugin: cordova add plugin cordova-plugin-whitelist

  2. Check config.xml has <access origin="*" /> (mine had it already)

  3. Add the CSP for ’ Enable all requests, inline styles, and eval()’ to in index.html as shown in https://github.com/apache/cordova-plugin-whitelist#content-security-policy

There is a lot of config shown at https://github.com/apache/cordova-plugin-whitelist but if you are just doing HTTP requests using $http (i.e. XHRs) and not navigating with URLs or spawning external URLs then you should be fine.


#7

Thanks a lot man. Haven’t tried it out but I read the documentation and it looks a lot like what I need. Thanks again.


#8

What if I’m making requests to a RESTful API using $resource. Thanks


#9

ok, thanks.

Very good