Search in sources :

Example 1 with PersistentCookieJar

use of com.risenb.expand.network.cookie.PersistentCookieJar in project AndroidFrame by tongxiaoyun.

the class m method initNetWorkWithCookie.

/**
 * 初始化网络控制器
 */
public m initNetWorkWithCookie(Context context) {
    // 持久化存储cookie
    ClearableCookieJar cookieJar = new PersistentCookieJar(new SetCookieCache(), new SharedPrefsCookiePersistor(context));
    // log拦截器
    HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
    logging.setLevel(HttpLoggingInterceptor.Level.BODY);
    // 自定义OkHttp
    OkHttpClient okHttpClient = new OkHttpClient.Builder().connectTimeout(10000L, TimeUnit.MILLISECONDS).readTimeout(10000L, TimeUnit.MILLISECONDS).cookieJar(// 设置开启cookie
    cookieJar).addInterceptor(// 设置开启log
    logging).build();
    netUtils = new MyOkHttp(okHttpClient);
    return instance;
}
Also used : MyOkHttp(com.risenb.expand.network.MyOkHttp) ClearableCookieJar(com.risenb.expand.network.cookie.ClearableCookieJar) OkHttpClient(okhttp3.OkHttpClient) PersistentCookieJar(com.risenb.expand.network.cookie.PersistentCookieJar) SetCookieCache(com.risenb.expand.network.cookie.cache.SetCookieCache) SharedPrefsCookiePersistor(com.risenb.expand.network.cookie.persistence.SharedPrefsCookiePersistor) HttpLoggingInterceptor(okhttp3.logging.HttpLoggingInterceptor)

Aggregations

MyOkHttp (com.risenb.expand.network.MyOkHttp)1 ClearableCookieJar (com.risenb.expand.network.cookie.ClearableCookieJar)1 PersistentCookieJar (com.risenb.expand.network.cookie.PersistentCookieJar)1 SetCookieCache (com.risenb.expand.network.cookie.cache.SetCookieCache)1 SharedPrefsCookiePersistor (com.risenb.expand.network.cookie.persistence.SharedPrefsCookiePersistor)1 OkHttpClient (okhttp3.OkHttpClient)1 HttpLoggingInterceptor (okhttp3.logging.HttpLoggingInterceptor)1