Search in sources :

Example 1 with SharedPrefsCookiePersistor

use of com.franmontiel.persistentcookiejar.persistence.SharedPrefsCookiePersistor in project okhttputils by hongyangAndroid.

the class MyApplication method onCreate.

@Override
public void onCreate() {
    super.onCreate();
    ClearableCookieJar cookieJar1 = new PersistentCookieJar(new SetCookieCache(), new SharedPrefsCookiePersistor(getApplicationContext()));
    HttpsUtils.SSLParams sslParams = HttpsUtils.getSslSocketFactory(null, null, null);
    //        CookieJarImpl cookieJar1 = new CookieJarImpl(new MemoryCookieStore());
    OkHttpClient okHttpClient = new OkHttpClient.Builder().connectTimeout(10000L, TimeUnit.MILLISECONDS).readTimeout(10000L, TimeUnit.MILLISECONDS).addInterceptor(new LoggerInterceptor("TAG")).cookieJar(cookieJar1).hostnameVerifier(new HostnameVerifier() {

        @Override
        public boolean verify(String hostname, SSLSession session) {
            return true;
        }
    }).sslSocketFactory(sslParams.sSLSocketFactory, sslParams.trustManager).build();
    OkHttpUtils.initClient(okHttpClient);
}
Also used : ClearableCookieJar(com.franmontiel.persistentcookiejar.ClearableCookieJar) OkHttpClient(okhttp3.OkHttpClient) LoggerInterceptor(com.zhy.http.okhttp.log.LoggerInterceptor) PersistentCookieJar(com.franmontiel.persistentcookiejar.PersistentCookieJar) SetCookieCache(com.franmontiel.persistentcookiejar.cache.SetCookieCache) SSLSession(javax.net.ssl.SSLSession) SharedPrefsCookiePersistor(com.franmontiel.persistentcookiejar.persistence.SharedPrefsCookiePersistor) HttpsUtils(com.zhy.http.okhttp.https.HttpsUtils) HostnameVerifier(javax.net.ssl.HostnameVerifier)

Aggregations

ClearableCookieJar (com.franmontiel.persistentcookiejar.ClearableCookieJar)1 PersistentCookieJar (com.franmontiel.persistentcookiejar.PersistentCookieJar)1 SetCookieCache (com.franmontiel.persistentcookiejar.cache.SetCookieCache)1 SharedPrefsCookiePersistor (com.franmontiel.persistentcookiejar.persistence.SharedPrefsCookiePersistor)1 HttpsUtils (com.zhy.http.okhttp.https.HttpsUtils)1 LoggerInterceptor (com.zhy.http.okhttp.log.LoggerInterceptor)1 HostnameVerifier (javax.net.ssl.HostnameVerifier)1 SSLSession (javax.net.ssl.SSLSession)1 OkHttpClient (okhttp3.OkHttpClient)1