我嘗試發送JSON對象休息服務,但我得到一些錯誤是這樣的:如何發送json對象從角度休息服務?
http://localhost:8080/api/v1/cardLimit 400(錯誤請求);
環繞到JSON
public class GameLimit implements Serializable {
private static final long serialVersionUID = 1L;
private LimitType firstLimit;
private LimitType secondLimit;
public LimitType getFirstLimit() {
return firstLimit;
}
public void setFirstLimit(LimitType firstLimit) {
this.firstLimit = firstLimit;
}
public LimitType getSecondLimit() {
return secondLimit;
}
public void setSecondLimit(LimitType secondLimit) {
this.secondLimit = secondLimit;
}
}
public class LimitType implements Serializable{
private static final long serialVersionUID = 1L;
private BigDecimal limit;
private String type;
private String status;
public BigDecimal getLimit() {
return limit;
}
public void setLimit(BigDecimal limit) {
this.limit = limit;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
}
限制請求對象
public class LimitReq extends GameLimit {
private String key;
public String getKey() {
return key;
}
}
RestController:
@RequestMapping(value = "/GameLimit", method = RequestMethod.POST)
public Response setCardLimit(@RequestBody GameLimitReq request) throws Exception {
return limitService.updateGameLimit(request);
}
打字稿客戶端:
changeLimits(firstLimit: IWidgetLimit, secondLimit: IWidgetLimit, key: string): ng.IPromise<any> {
return this.$http.post(this.apiPrefix + '/GameLimit', {
'firstLimit': {
limit: firstLimit.limit,
type: firstLimit.type,
status: firstLimit.status
},
'secondLimit': {
limit: secondLimit.limit,
type: secondLimit.type,
status: secondLimit.status,
},
key: key
}).then(function (response: any) {
return response.data;
}.bind(this));
}
是什麼請求看起來像在瀏覽器控制檯/網絡選項卡?你的物體是否正確張貼? –
@Alex R不,我得到像這樣的錯誤http:// localhost:8080/api/v1/cardLimit 400(Bad Request); 如果我設置爲null'firstLimit':null,'secondLimit':爲我嘗試ro的每個對象發送null null,'secondLimit'發送它與成功的交易但如果我設置對象我得到像http:// localhost:8080/api/v1/cardLimit 400(Bad Request); a – tiger
400響應來自您的API,我正在討論在獲得400響應之前發送到API的傳出請求 –