2017-09-10 9 views
0

에 실패 이것은 내가 POST 요청에 전달하고있는 JSON 문자열 :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 (Unprocessable Entity) 오류가 발생했습니다.

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" 
    }, 

동일한 JSON 문자열이 작동합니다. 우체부에서 사용할 때 성공합니다.

답변

0

리소스 인스턴스 대신 리소스 클래스를 사용하여이 문제를 해결할 수있었습니다.