小编aw4*_*w4y的帖子

android - OkHttp拦截器 - 响应已经"消耗"

我正在尝试使用此拦截器进行身份验证:

public class CustomInterceptor implements Interceptor {

@Override
public Response intercept(Chain chain) throws IOException {
    Request request = chain.request();

    // try the request
    Response response = chain.proceed(request);

    if (response shows expired token) {

        // get a new token (I use a synchronous Retrofit call)

        // create a new request and modify it accordingly using the new token
        Request newRequest = request.newBuilder()...build();

        // retry the request
        return chain.proceed(newRequest);
    }

    // otherwise just pass the original response on
    return response;
}
Run Code Online (Sandbox Code Playgroud)

问题是我的检查(响应显示过期令牌)与状态无关,我需要检查实际响应(正文内容).因此,在检查之后,响应被"消耗"并且任何准备身体的尝试都将失败. …

android response interceptor okhttp

16
推荐指数
1
解决办法
3573
查看次数

标签 统计

android ×1

interceptor ×1

okhttp ×1

response ×1