【发布时间】:2016-02-12 21:24:38
【问题描述】:
我知道有很多类似的问题,但没有一个对我有帮助。
在服务器上我有方法:
@RequestMapping(value = "/event", method = RequestMethod.POST , produces = MediaType.APPLICATION_JSON_VALUE)
public void bookOpened(
@RequestParam(value="id", required = true) int id,
@RequestParam(value="type", required = true) String type,
HttpServletRequest request, HttpServletResponse response, HttpSession httpSession) {
}
在客户端我发送一个请求:
var xhr = new XMLHttpRequest();
xhr.open('POST', '/event');
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.onload = function() {
if (xhr.status === 200) {
var userInfo = JSON.parse(xhr.responseText);
console.log(userInfo);
}
};
xhr.send(JSON.stringify({
id: 1,
type: 'BOOK_VIEWED'
}));
请求以错误 400(错误请求)结束,我不知道为什么
【问题讨论】: