[英]Invalid JSON, 400 Bad request in Angular $http.post
This is my data object - 这是我的数据对象-
var bill = { "type":"insert", "args": { "table": "finance_data", "objects": [ { "title": $scope.data.title, "url": $scope.data.url, "type":"payments" } ] } };
This is my config object- 这是我的配置对象-
var config = { headers:{ 'Authorization' : "Bearer "+ $localStorage.auth_token, } };
I'm doing a POST request to my server to insert data into a table ( db: PostgreSQL) This is my http request code- 我正在对服务器执行POST请求,以将数据插入表中(数据库:PostgreSQL),这是我的http请求代码-
$http.post('https://data.saarang.org/v1/query', bill, config).then(function(response){ console.log('success'); alert('Successfully uploaded the Payment Receipt!'); $state.reload(); }).catch(function(err){ console.log(err); });
Object { data: Object, status: 400, headers: headersGetter/<(), config: Object, statusText: "Bad Request" }
The err.data object has an error message - 'invalid JSON' The bill object has all the fields that are required but still the server throws back an "invalid JSON" error Please Help ! err.data对象有一条错误消息-“无效的JSON”帐单对象具有所有必填字段,但服务器仍抛出“无效的JSON”错误,请帮助!
I found the solution myself, it wasn't any backend/server related issue, the url key in the object was supposed to be Url . 我自己找到了解决方案,这不是任何与后端/服务器相关的问题,对象中的url键应该是Url 。 The typo caused an invalid JSON error. 错字导致无效的JSON错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.