SOLVED: Error 404 when sending data with $http.post

Hello everyone.

I have a problem that I can not solve. Well, actually I’m not sure could be. The strange thing is that everything is fine using curl.

Here my service within the controller.

$scope.signIn = function(user) {

    var url_service = "http://dominio.com/services_qp/";
    
// user : contains the form data 
    $http.post(url_service + "login2", user)
        .success(function(responseData) {
            if (responseData == 'false') {
                $ionicLoading.show({ 
                    template: 'Error',
                    noBackdrop: true,
                    duration: 2000 
                });
            }
            else{
                console.log(responseData);
            }
        })
        .error(function(err) {
            console.log(err);
            $ionicLoading.show({ 
                template: 'Something',
                noBackdrop: true,
                duration: 2000 
            });
        });
};

By using the above code, I get the error 404 But if sending this form, everything works fine and returns me data.

curl -i -X POST -H 'Content-Type: application/json' -d '{"email": "usuario@gmail.com", "clave": "12345"}' http://dominio.com/services_qp/login2

HTTP/1.1 200 OK
Date: Thu, 18 Sep 2014 18:50:02 GMT
Server: Apache/2.2.14 (Ubuntu)
X-Powered-By: PHP/5.3.2-1ubuntu4.27
Access-Control-Allow-Origin: *
Vary: Accept-Encoding
Content-Length: 118
Content-Type: text/html

{"iduser":"1","status":"Dream Code xD","photo":"http:\/\/dominio.com\/services_qp\/img_user\/jmc.jpg"}

There a right way to do this.

Ok, I found the solution, I had not seen examples of this type. I think I need to deepen angularjs

$http.post(url_service + "login2", user, {
            headers: { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'}
        })

is all. Fixed.

1 Like

I had to install the whitelist plugin to get the APIs to call properly on my device. I also added the proper meta tags in my index.html file.

@ Sean_antony Thank you so much buddy i wasted all my day in it…and finally your solution.