美文网首页
Retrofit intercept替换url

Retrofit intercept替换url

作者: 山东好汉Tim | 来源:发表于2018-03-29 00:17 被阅读22次
    public class DomainInterceptor implements Interceptor {
        public static final String TAG = "DomainInterceptor";
        
        @Override
        public Response intercept(Chain chain) throws IOException {
    
            Request request = chain.request();
    
            if(true){
                Request.Builder builder = request.newBuilder();
    
    
             //   String url = list.get(new Random().nextInt(list.size()));
                
                HttpUrl newBaseUrl = HttpUrl.parse(url);
                
                HttpUrl oldHttpUrl = request.url();
                HttpUrl newFullUrl = oldHttpUrl
                        .newBuilder()
                        .scheme(newBaseUrl.scheme())
                        .host(newBaseUrl.host())
                        .port(newBaseUrl.port())
                        .build();
    
                Response response = chain.proceed(builder.url(newFullUrl).build());
    
                return response;
    
            }else {
                return chain.proceed(request);
            }
        }
    }

    相关文章

      网友评论

          本文标题:Retrofit intercept替换url

          本文链接:https://www.haomeiwen.com/subject/csypcftx.html