Reputation: 679
I have Cordova > 4.0.0, so it has CSP and Whitelist security measures.
In the browser I can make the request to the API, but in an Android device it gives me this error:
file:///http:/xxx.xxx.xxx/api/Login/DoLogin
Failed to load resource: net::ERR_FILE_NOT_FOUND
I searched for a solution, but nothing worked.
My config.xml has this fields (according to Cordova Whitelist Plugin documentation):
<allow-navigation href="*" />
<allow-intent href="*" />
<access origin="*" />"
INFO: I tryed multiple combination's of this parameter's, with the URL of the Api.
(Ex: <access origin="http://xxx.xxx.xxx/" subdomains="true" />
)
In my Index.html I have this CSP:
<meta http-equiv="Content-Security-Policy"
content="default-src *; style-src * 'self' 'unsafe-inline' 'unsafe-eval';
script-src * 'self' 'unsafe-inline' 'unsafe-eval';">
INFO: In here I have tried other combination's of CSP according to Cordova Whitelist Plugin
So, before anyone ask I have installed:
And using Restangular for the requests.
I can't figure it out, can someone help me?
EDIT: Request Code
var baseLogin = Restangular.all('http:/xxx.xxx.xxx/api/Login/DoLogin');
dataApi.doLogin = function (var1, var2, var3, var4, var5) { // $http() returns a $promise that we can add handlers with .then() var parameter = null; parameter = { var1: var1, var2: var2, var3: var3, var4: var4, var5: var5 }; return baseLogin.post(parameter); };
I use Ionic, so it has CORS issues in browser, to resolve that I use a proxy in ionic.project file, but it's only called in the browser, in the device it is not using this.
Upvotes: 3
Views: 1384
Reputation: 427
Try to remove the "file" from your url, as @Phonolog commented out.
It's not necessary and it may be causing an internal exception on the phone. Try to use just http:/xxx.xxx.xxx/api/Login/DoLogin, as you would with an WCF service. Also be sure that this endpoint is properly configured to accept incoming requests.
Addendun: Also, you should be careful with these tags:
<allow-navigation href="*" />
<allow-intent href="*" />
<access origin="*" />"
These means allowing access to everything, and also allows communications with others applications/services. So be careful, this can cause a security issue in the future.
Upvotes: 1