这是我传递给 POST 请求的 JSON 字符串:
var data = {
"location": {
"value": {
"href": "http://localhost:8080/restful/objects/businessentities.Location/47"
}
},
"asset": {
"value": {
"href": "http://localhost:8080/restful/objects/businessentities.Asset/36"
}
}
}
AngularJS 资源代码是:
var AuditItemCreate = $resource(
apiUrl + '/restful/services/domainapp.dom.BusinessEntities.AuditItemMenu/actions/create/invoke/');
var a2 = new AuditItemCreate();
a2.$save(data)
.then(function(res) { console.log("success") })
.catch(function(req) { console.log("error saving obj: " + JSON.stringify(req, null, 4)); })
但是我收到服务器响应 422(无法处理的实体)错误:
error saving obj: {
"data": {
"asset": {
"value": "{\"value\":{\"href\":\"http://localhost:8080/restful/objects/businessentities.Asset/36\"}}",
"invalidReason": "Expected a link (because this object's type is not a value) but found no 'href'"
},
"location": {
"value": "{\"value\":{\"href\":\"http://localhost:8080/restful/objects/businessentities.Location/47\"}}",
"invalidReason": "Expected a link (because this object's type is not a value) but found no 'href'"
},
"x-ro-invalidReason": "Mandatory"
},
在 Postman 中使用时,相同的 JSON 字符串可以成功运行。