将 Apache HttpClient 响应拦截器与请求匹配
Matching Apache HttpClient Response Interceptor to Request
Apache HttpClient 具有具有此方法的 HttpResponseInterceptor 接口。
void process(HttpResponse response, HttpContext context)
如何获取生成此 HttpResponse 实例的 HttpRequest 实例?
HttpClients.custom()
.addInterceptorLast((HttpResponseInterceptor)(response, context) -> {
// how to get matching request?
})
.build();
可以从执行上下文中获取实际的 HTTP 请求消息以及其他请求执行详细信息:
HttpClients.custom()
.addInterceptorLast((HttpResponseInterceptor) (response, context) -> {
final HttpClientContext clientContext = HttpClientContext.adapt(context);
final HttpRequest request = clientContext.getRequest();
})
.build();
Apache HttpClient 具有具有此方法的 HttpResponseInterceptor 接口。
void process(HttpResponse response, HttpContext context)
如何获取生成此 HttpResponse 实例的 HttpRequest 实例?
HttpClients.custom()
.addInterceptorLast((HttpResponseInterceptor)(response, context) -> {
// how to get matching request?
})
.build();
可以从执行上下文中获取实际的 HTTP 请求消息以及其他请求执行详细信息:
HttpClients.custom()
.addInterceptorLast((HttpResponseInterceptor) (response, context) -> {
final HttpClientContext clientContext = HttpClientContext.adapt(context);
final HttpRequest request = clientContext.getRequest();
})
.build();