Getting status code 0 on $http post request with whitelist plugin installed in the android device

Hello everyone,

Need quick replies on this one. I have created an apk which is basically pointing to an online server but when I am making a $http post request, it is gives me a status code of 0 and null data.

This app build is working fine when I am pointing it to a local server. I have already used Whitelist plugin which was working fine previously with my old codebase.
Here is the $http method that I am using in my controller

$http({
            method: 'POST',
            url: HOST_NAME+'/user/signin',
            data: LoginData
        }).success(function(data, status, headers, config) {
            $ionicLoading.hide();
            if (data.error == false) {
                localStorage.isAuthenticated = true;
                localStorage.authToken = data.token;
                $state.go('app.home.dash', {}, {
                    reload: true,
                    inherit: false
                });
                console.log(data.error);
            } else {
                $scope.formData.errors = {};
                var errorMsg = data.msg;
                $scope.formData.error = errorMsg;
            }
        }).error(function(data, status, headers, config) {
            // console.log(JSON.stringify(data));
            $ionicLoading.hide();
            $scope.formData.errors = {};
            if (status == 401 || status == 400) {
                $scope.formData.error = "INVALID CREDENTIALS";
            } else if (status === 0 || status === 404) {
                $scope.formData.error = "CONNECTION ERROR " + status;
            } else {
                $scope.formData.error = "THERE WAS AN ERROR, STATUS CODE: " + status;
            }
        });

Please, help me on this.
Thank You

Have you used an appropriate whitelist security meta tag in your index.html HEAD?

Hi Gajotres, yes I have added the meta tags that are required. I am not sure why it is not even making a post request. I think the CORS is blocking the entire post call here.
By the way I follow your great blog as well.

Thanks for the reply.
Keep up the good work

Hi,I have the same problem…I wanted to know if and how you solved it

Thanks a lot

Hi @Ferrante1, the issue with my app was the inconsistency of the functionality of whitelist plugin because of the incorrect inclusion of it, which means running the plugin before the entire app is actually ready.
So, make sure your all plugins loads before the entire angular app is ready.

1 Like