public class LogInterceptor implements Interceptor {
@Override
public Response intercept(Chain chain) throws IOException {
Request request = chain.request();
//请求之前
//打印系统时间
Log.d(“LogInterceptor”, “System.nanoTime():” + System.nanoTime());
//打印头部信息
Headers headers = request.headers();
String type = headers.get(“content-type”);
String cache = headers.get(“cache-control”);
Log.d(“LogInterceptor”, type + “……” + cache);
//请求之后
Response response = chain.proceed(request);
//打印系统时间
Log.d(“LogInterceptor”, “System.nanoTime():” + System.nanoTime());
return response;
}
}
public class RedirectInterceptor implements Interceptor {
@Override
public Response intercept(Chain chain) throws IOException {
//1.Chain可以获取请求过程中的所有细节
Request request = chain.request();
//获取新请求
Request newRequest = request.newBuilder()
//将请求地址重新指向福利接口
.url(Constant.BEAUTY_URL)
.build();
//将新请求挂载到请求队列上
Response response = chain.proceed(newRequest);
return response;
}
}