java如何在HandlerInterceptor的afterCompletion()中获取响应数据
我试图在Spring HandlerInterceptor的afterCompletion()中获取响应数据,但获取的数据为空
@Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
try {
ContentCachingRequestWrapper requestWrapper = new ContentCachingRequestWrapper(request);
byte[] contentAsByteArray = responseWrapper.getContentAsByteArray();
} finally {
SessionManagerThreadLocal.remove();
}
}
contentAsByteArray字节[]为空
我该怎么办?谢谢
# 1 楼答案
在您的描述中,您说您正在尝试获得响应,但在代码中,您使用的是请求和请求映射器。如果您想使用请求,您需要添加过滤器,它将请求存储在包装器中