简体   繁体   中英

$http.post 400 empty json body at server

Can anyone tell me what is wrong with this $http.post call? I get a bad reaquest and the server gets an empty json body.

var data = JSON.stringify({

            "Name" : $scope.device.ChildName,
            "Serial" : $scope.device.Serial

        });

        console.log($scope.device.Serial);
        console.log($scope.device.ChildName);
        console.log(data);

        $http.post('http://141.135.5.117:3500/device/register', data, { headers: headers })
        .then(function(response){
            console.log(response);
            console.log(headers);




        });

This are my headers

var headers = {
            "Content-Type": "application/json;" ,
            "Authorization" : JWT

    };

Note: JWT is for Authorization.

Thanks

It works!

Don't know exactly why, but maybe because of this:

I've deleted the Content-type argument in the headers. And now it works.

I'v read somewhere that http post is standard in JSON format. And you'll overwrite this in the headers and this causes for errors?

You're stringifying the object but sending it as application/json. Just send the data without stringifying it and I think the issue will be resolved

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM