我正在使用contentcachingresponsewrapper以继承的方式读取响应信息 OncePerRequestFilter.doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
水平。最后我会给你打电话 ContentCachingResponseWrapper.copyBodyToResponse()
复制响应体。当我使用springcloudopenfeignweb客户端进行api调用时,就会发生这种情况。因此get响应在头文件中包含“传输编码”,然后在调用 ContentCachingResponseWrapper.copyBodyToResponse()
它将“内容长度”添加到标题中。
然后我得到以下错误;
分析错误:响应头不能包含具有分块编码的“内容长度”
我的代码如下:;
onceperrequestfilter重写方法;
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
throws ServletException, IOException
{
ContentCachingRequestWrapper requestWrapper = new ContentCachingRequestWrapper(request);
ContentCachingResponseWrapper responseWrapper = new ContentCachingResponseWrapper(response);
try
{
if (ocpHttpTraceService.isLoggingPropertyEnabled(TracingConstants.BODY, TraceType.INBOUND))
{
filterChain.doFilter(requestWrapper, responseWrapper);
}
else
{
filterChain.doFilter(request, response);
}
System.out.println(getRequestBody(requestWrapper));
System.out.println(getResponseBody(responseWrapper));
}
finally
{
responseWrapper.copyBodyToResponse();
}
}
暂无答案!
目前还没有任何答案,快来回答吧!