jeasonlzy / okhttp-OkGo

OkGo - 3.0 震撼来袭,该库是基于 Http 协议,封装了 OkHttp 的网络请求框架,比 Retrofit 更简单易用,支持 RxJava,RxJava2,支持自定义缓存,支持批量断点下载管理和批量上传管理功能
Apache License 2.0
10.59k stars 2.55k forks source link

如何禁止302重定向? #943

Open xiaoli-style opened 4 years ago

xiaoli-style commented 4 years ago

如何禁止重定向呢?我想截获重定向的location地址

rimuweinuan commented 3 years ago

在初始化okgo的时候加个拦截器: image

拦截器的内容如下: public class RedirectIntercepter implements Interceptor { private Context context; public RedirectIntercepter(Context context) { this.context = context; } @Override public Response intercept(Chain chain) throws IOException { Response response = chain.proceed(chain.request()); if (!TextUtils.equals(chain.request().url().toString(),response.request().url().toString())) { 接口302做处理。 } return response; } }