404 error for an existing url calling from cordova

2019-09-04 07:20发布

问题:

This question already has an answer here:

  • Refused to connect to [Any Url] because it violates the following Content Security Policy directive 1 answer

Here is my angular controller of a cordova app

angular.module('mobApp.controllers', ['ionic'])
.controller('SignupController', function($scope, $http, $location) {

        $scope.submitCommonSignUpForm = function(isValid, formData) {
            if (isValid) {
                var d = formData;
                $http.post('http://X.X.X.X/api/v1.0/basicSignup',formData).
                then(function(d){

                }).
                then(function(e){

                });
            }
        };  

});

I am getting 404 for http://X.X.X.X/api/v1.0/basicSignup but the fact is it exist. Any idea why ?

In my app Inside platform > android > res > config.xml i haveset <access origin="*" />

回答1:

You need to install the whitelist plugin from Cordova.

See my previous answer regarding this:

You need to install the whitelist plugin to allow XHR support in your Cordova app. You can't make external requests without it.

Run: cordova plugin add https://github.com/apache/cordova-plugin-whitelist.git