简体   繁体   English

$ http.post服务器上的400个空json主体

[英]$http.post 400 empty json body at server

Can anyone tell me what is wrong with this $http.post call? 谁能告诉我$ http.post电话有什么问题吗? I get a bad reaquest and the server gets an empty json body. 我遇到了不好的请求,服务器得到了一个空的json主体。

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. 注意:JWT用于授权。

Thanks 谢谢

It works! 有用!

Don't know exactly why, but maybe because of this: 不知道为什么,但是也许是因为这个:

I've deleted the Content-type argument in the headers. 我已经删除了标题中的Content-type参数。 And now it works. 现在就可以了。

I'v read somewhere that http post is standard in JSON format. 我读过某个地方,http帖子是JSON格式的标准内容。 And you'll overwrite this in the headers and this causes for errors? 并且您将在标题中覆盖它,这会导致错误?

You're stringifying the object but sending it as application/json. 您正在对对象进行字符串化,但是将其作为application / json发送。 Just send the data without stringifying it and I think the issue will be resolved 只需发送数据而不进行字符串化,我认为问题将得到解决

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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