Http POST Connection ERROR


#1

Hello, thanks to all community for the help.

I have a problem with my controller, when I try to ‘sig in’ in my app using the movil device, I can not connect with the server, but when I try the same code in the browser I do not have problem to connect or work with the app.
This problem only appear when I am working from movil device.

This is my controller code:

.controller(‘LoginCtrl’, function($scope, $state, $http, UserFtry) {
$scope.logIn = function(user){
$scope.user = {};
$scope.user.username = “”;
$scope.user.password = “”;

    if(user == null){
        $scope.user.response = "Debe rellenar los campos Usuario y Contraseña.";
        $scope.user.username = "";
        $scope.user.password = "";
    }else{
        return $http({            
            url : '/loginAccess', 
            method : 'POST', 
            data : {'usuario': user.username,'password': user.password},
            headers : { 'Content-Type' : 'application/json' }
        }).success(function(result) {
            if (result == "Error"){
                $scope.user.response = "Usuario o contraseña incorrectos.";
                $scope.user.usuario = "";
                $scope.user.password = "";
            }else{
                UserFtry.data.usuario = result[0];
                $state.go('tab.home');
            }
        }).error(function(result){
            $scope.user.response = "Error de conexión";
        });
    }
};

})

I have tried different codes but I always get the same result. I can not obtain the success result, only error, as I said this only happens on movil device.

I am working in ANDROID platform.

Thanks for all.


#2

does you have added the whitelist plugin to your project?

You have to allow outgoing requests to your server


#3

Assuming you get your white-list plugin setup correctly, I still had to disable the user of my proxy.

Are you using a proxy in your ionic.project to map “/loginAccess” to some http://server.com?

When I deploy to android, I have to do two things. Turn off the proxy, and change my URL to the full server url.


#4

Thanks for all, I can already solved this problem.
The problem was in the proxies that need to be turned off to create the package, and use the server URL instead off the proxy address.

Now work correctly in the mobile device.