Browse Source

RetrofitFactory.java

niusongtao@dl-cg.com 4 years ago
parent
commit
53f8620f57

+ 1 - 0
base_library/build.gradle

@@ -126,6 +126,7 @@ dependencies {
     api 'com.aliyun.dpa:oss-android-sdk:+'
 
     api 'com.airbnb.android:lottie:3.5.0'
+//    api 'com.github.franmontiel:PersistentCookieJar:v1.0.1'
     
     testImplementation lib.junit
     androidTestImplementation lib.runner

+ 13 - 0
base_library/src/main/java/com/mgtech/base_library/http/common/RetrofitFactory.java

@@ -5,14 +5,19 @@ import com.google.gson.Gson;
 import com.google.gson.GsonBuilder;
 import com.mgtech.base_library.contextUtil.ContextUtils;
 import com.mgtech.base_library.http.interceptor.InterceptorUtil;
+import com.zhy.http.okhttp.cookie.store.PersistentCookieStore;
 
 import java.io.File;
+import java.net.CookieHandler;
+import java.net.CookieManager;
+import java.net.CookiePolicy;
 import java.util.concurrent.TimeUnit;
 
 import io.reactivex.ObservableTransformer;
 import io.reactivex.android.schedulers.AndroidSchedulers;
 import io.reactivex.schedulers.Schedulers;
 import okhttp3.Cache;
+import okhttp3.CookieJar;
 import okhttp3.OkHttpClient;
 import retrofit2.Retrofit;
 import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
@@ -35,6 +40,13 @@ public class RetrofitFactory {
     private Retrofit mRetrofit;
 
     private RetrofitFactory(){
+//        CookieHandler cookieHandler = new CookieManager(new PersistentCookieStore(ContextUtils.getContext()),
+//                CookiePolicy.ACCEPT_ALL);
+
+
+//        CookieJar cookieJar =
+//                new PersistentCookieJar(new SetCookieCache(), new SharedPrefsCookiePersistor(ContextUtils.getContext()));
+
         //设置缓存路径
         File httpCacheDirectory = new File(ContextUtils.getContext().getCacheDir(), "HttpCache");
         //设置缓存 10M
@@ -48,6 +60,7 @@ public class RetrofitFactory {
                 .addInterceptor(InterceptorUtil.cacheInterceptor())
                 .addNetworkInterceptor(InterceptorUtil.cacheNetInterceptor())
                 .cache(cache)
+//                .cookieJar(cookieJar)
                 .build();
 
         Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm:ss").serializeNulls().create();