【发布时间】:2013-12-05 13:50:52
【问题描述】:
当请求包含Content-Type=application/x-www-form-urlencoded时,我无法获取请求正文内容。
我有以下检索请求正文的方法:
@RequestMapping(value = "/testRequestBody", method = RequestMethod.POST)
@ResponseBody
public String testRequestBody(@RequestBody String requestBody) {
return requestBody;
}
我正在使用 restclient firefox 插件来测试请求。当我将Content-Type=application/x-www-form-urlencoded 添加到请求时,requestBody 变量变为空,尽管我在请求正文中有文本。当我删除 Content-Type 标头时,请求正文会填充文本。
UPD
这个问题似乎与用于运行spring容器的tomcat有关。当application/x-www-form-urlencoded请求到来时,解析,body中定义的参数成为请求参数,然后body被清除。
我可以通过以下方式访问正文参数:
@RequestMapping(value = "/testRequestBody", method = RequestMethod.POST)
@ResponseBody
public String testRequestBody(@RequestParam("paramName") String paramName) {
return requestParam;
}
如何配置tomcat不解析请求,不清除请求体?
【问题讨论】:
-
我面临同样的问题。有人知道
How can I configure tomcat not to parse request and not to clear request body?的答案
标签: java spring spring-mvc