重点已经画圈
/**
* 获取okHttpClient
*
* @return the ok http client
*/
private final static int CACHE_SIZE_BYTES = 1024 * 1024 * 2;
public static OkHttpClient getOkHttpClient() {
if (okHttpClient == null) {
okHttpClient = new OkHttpClient.Builder()
.connectTimeout(15, TimeUnit.SECONDS)
.readTimeout(15, TimeUnit.SECONDS)
.retryOnConnectionFailure(true)
.writeTimeout(15, TimeUnit.SECONDS)
.addInterceptor(new TokenInterceptor())
.cache(new Cache(context.getCacheDir(),CACHE_SIZE_BYTES))
.addNetworkInterceptor(new HttpLoggingInterceptor())
.build();
}
return okHttpClient;
}