有没有人知道 spring自带的restTemplate发送请求后,怎么获取完整的请求头信息啊?
注意 是 “完整的” “请求头”,不是响应头!
获取响应头吧。。使用 xxxForEntity方法,获取返回的ResponseEntity对象,这个对象封装了完整的响应信息,可以访问响应头。
抓包
请求拦截器?
@Slf4j
static class HttpInterceptor implements ClientHttpRequestInterceptor {
@Override
public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException {
log.info("请求地址:{}", request.getURI());
log.info("请求方法: {}", request.getMethod());
log.info("请求内容:{}", new String(body));
log.info("请求头:{}", request.getHeaders());
return execution.execute(request, body);
}
}