谁能告诉我这个 $http.post 调用有什么问题吗? 我收到一个错误的请求,服务器得到一个空的 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);
});
这是我的标题
var headers = {
"Content-Type": "application/json;" ,
"Authorization" : JWT
};
注意:JWT 用于授权。
谢谢
最佳答案
有效!
不知 Prop 体原因,但可能是因为这个:
我删除了标题中的 Content-type 参数。 现在它起作用了。
我在某处读到,http post 是 JSON 格式的标准。您将在 header 中覆盖此内容,这会导致错误吗?
关于javascript - $http.post 400 服务器上的空 json 正文,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44145090/