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);
}
}
}
网友评论