//懒汉式
private static volatile HttpUtils instance;
private OkHttpClient client;
private Handler handler = new Handler(Looper.getMainLooper());
//这里面我加上了日志拦截器
private HttpUtils() {
HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
client = new OkHttpClient.Builder()
.connectTimeout(5, TimeUnit.SECONDS)
.addInterceptor(interceptor)
.build();
}
public static HttpUtils getInstance() {
if (instance == null) {
synchronized (HttpUtils.class) {
if (null == instance) {
instance = new HttpUtils();
}
}
}
return instance;
}
}