gpt4 book ai didi

java - 将 Apache HttpClient 响应拦截器与请求相匹配

转载 作者:行者123 更新时间:2023-12-02 02:01:45 29 4
gpt4 key购买 nike

Apache HttpClient 的 HttpResponseInterceptor 接口(interface)具有此方法。

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();

关于java - 将 Apache HttpClient 响应拦截器与请求相匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57371002/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com