retrofit和okhttp的区别
1个回答
2017-09-07 · 知道合伙人金融证券行家
关注
展开全部
private static OkHttpClient mOkHttpClient;
//短缓存有效期为1秒钟
public static final int CACHE_STALE_SHORT = 1;
//长缓存有效期为7天
public static final int CACHE_STALE_LONG = 60 * 60 * 24 * 7;
private MyRetrofitManager() {
initOkHttpClient();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(BASE_NIUPAI_URL)
.client(mOkHttpClient)
.addCallAdapterFactory(RxJavaCallAdapterFactory.create())
// .addConverterFactory(new MyCustomFactory())
.addConverterFactory(GsonConverterFactory.create())
.build();
mJtmlService = retrofit.create(JtmlServer.class);
}
private void initOkHttpClient() {
HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
if (mOkHttpClient == null) {
synchronized (MyRetrofitManager.class) {
if (mOkHttpClient == null) {
// 指定缓存路径,缓存大小100Mb
Cache cache = new Cache(new File(App.getContext()。getCacheDir(), "HttpCache"),
1024 * 1024 * 100);
mOkHttpClient = new OkHttpClient.Builder()
.cache(cache)
.addInterceptor(mRewriteCacheControlInterceptor)
.addNetworkInterceptor(mRewriteCacheControlInterceptor)
.addInterceptor(interceptor)
.retryOnConnectionFailure(true)
.connectTimeout(15, TimeUnit.SECONDS)
.build();
}
}
}
//短缓存有效期为1秒钟
public static final int CACHE_STALE_SHORT = 1;
//长缓存有效期为7天
public static final int CACHE_STALE_LONG = 60 * 60 * 24 * 7;
private MyRetrofitManager() {
initOkHttpClient();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(BASE_NIUPAI_URL)
.client(mOkHttpClient)
.addCallAdapterFactory(RxJavaCallAdapterFactory.create())
// .addConverterFactory(new MyCustomFactory())
.addConverterFactory(GsonConverterFactory.create())
.build();
mJtmlService = retrofit.create(JtmlServer.class);
}
private void initOkHttpClient() {
HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
if (mOkHttpClient == null) {
synchronized (MyRetrofitManager.class) {
if (mOkHttpClient == null) {
// 指定缓存路径,缓存大小100Mb
Cache cache = new Cache(new File(App.getContext()。getCacheDir(), "HttpCache"),
1024 * 1024 * 100);
mOkHttpClient = new OkHttpClient.Builder()
.cache(cache)
.addInterceptor(mRewriteCacheControlInterceptor)
.addNetworkInterceptor(mRewriteCacheControlInterceptor)
.addInterceptor(interceptor)
.retryOnConnectionFailure(true)
.connectTimeout(15, TimeUnit.SECONDS)
.build();
}
}
}
Storm代理
2023-05-25 广告
2023-05-25 广告
StormProxies是全球大数据IP资源服务商,其住宅代理网络由真实的家庭住宅IP组成,可为企业或个人提供满足各种场景的代理产品。点击免费测试(注册即送1G流量)StormProxies有哪些优势?1、IP+端口提取形式,不限带宽,IP...
点击进入详情页
本回答由Storm代理提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询