HttpMessageNotReadableException:缺少所需的请求正文(偶尔)-SpringMVC 默认控制器请求映射 HTTP 方法? [英] HttpMessageNotReadableException: Required request body is missing (Occasional) - SpringMVC Default Controller Request Mapping HTTP Method?
问题描述
我有以下代表 Ajax POST 请求的代码:
I have the following code which represents an Ajax POST request:
@RequestMapping("/participant/insertEvent")
public boolean insertEvent(Principal principal, @RequestBody String json, HttpServletRequest request) throws Exception {
//...
//return true or false
}
JS:
$.ajax({
type : "post",
dataType : "json",
url : '/app/participant/insertEvent',
data : JSON.stringify({'p1': p1, 'p2' : p2})
});
该应用已部署到生产环境中,整个星期以来,许多用户都在使用它.
The app is deployed in Production and everything has been working with many users the whole week.
今天早上我在这个方法 (insertEvent
) 上遇到了以下生产问题:
This morning I got the following production issue at this method (insertEvent
):
org.springframework.http.converter.HttpMessageNotReadableException: Required request body is missing: public boolean
app.controller.participant.AjaxOperationsController.insertEvent(java.security.Principal,java.lang.String,javax.servlet.http.HttpServletRequest) throws java.lang.Exception at
org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.readWithMessageConverters(RequestResponseBodyMethodProcessor.java:161) at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.resolveArgument(RequestResponseBodyMethodProcessor.java:130) at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:124) at
org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:161) at ...
我在想,是不是因为我没有明确指定这是一个 method={RequestMethod.POST}
?
I'm wondering, is it because I didn't explicitly specify this is a method={RequestMethod.POST}
?
但是如果我不指定 HTTP 方法,默认是什么?
But if I don't specify an HTTP method, what is the default?
但是,如果这是问题所在,那么为什么该应用可以在 99% 的时间内运行,而不是为那个用户运行?
However, if this is the issue, then why does the app work 99% of the time, and not for that one user?
推荐答案
仅供参考,该错误是由于在 JSON 中包含来自 TextArea 值的未编码的 %(百分比)特殊字符引起的.
FYI, the error was caused by including in the JSON an un-encoded % (percent) special char coming from a TextArea value.
这篇关于HttpMessageNotReadableException:缺少所需的请求正文(偶尔)-SpringMVC 默认控制器请求映射 HTTP 方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!