https://www.iteye.com/blog/liwx2000-1542431
最近使用spring mvc做项目,数据格式是json,有一个功能是实现记录请求的参数,而请求的参数是整个RequestBody,Controller里是用过@RequestBody获取的。实现方法是通过一个Filter读取整个RequestBody并记录。但是这时就遇到一个问题,ServletRequest的getReader()和getInputStream()两个方法只能被调用一次,而且不能两个都调用。那么如果Filter中调用了一次,在Controller里面就不能再调用了。查看了下ServletRequest的说明,如下:
Java代码
- /**
- * Retrieves the body of the request as binary data using
- * a {@link ServletInputStream}. Either this method or
- * {@link #getReader} may be called to read the body, not both.
- *
- * @return a {@link ServletInputStream} object containing
- * the body of the request
- *