【发布时间】:2017-12-01 20:52:09
【问题描述】:
我试图在我的拦截器中拦截一个特定的请求。我想捕捉401 http状态,这很容易做到
response.code()
但是,我还需要检查负载中的特定字段,但我找不到如何检索此负载。
这是我的拦截器:
Interceptor authorizationInterceptor = new Interceptor() {
@Override
public Response intercept(Chain chain) throws IOException {
Request request = chain.request();
okhttp3.Response response = chain.proceed(request);
if (response.code() == 401) {
// I need to access the payload here
return response;
}
return response;
}
};
能找回来吗?
【问题讨论】:
-
response.body().string()呢?请记住,它将消耗响应的正文 -
@Selvin 这正是我所需要的,谢谢