【发布时间】:2022-01-03 11:40:42
【问题描述】:
我在 3.14.9 版本中有一些关于 okhttp 的使用问题 如果我想为每个请求添加 LoggingInterceptor,我怎样才能得到响应体,它只能消耗一次?
接下来是我的尝试
public class LoggingRequestInterceptor implements Interceptor {
@Override
public Response intercept(Chain chain) throws IOException {
Request request = chain.request();
Response response = chain.proceed(request);
log.debug(
"{}, {}, {}, {}, {}, {}, {}",
request.url(),
request.method(),
JSONUtil.toJsonStr(request.body()),
request.headers(),
dup.body() == null ? null : dup.body().string());
return response;
}
}
会抛出stream关闭的异常,如何解决?
【问题讨论】:
标签: okhttp