com.franmontiel.persistentcookiejar.ClearableCookieJar Java Examples
The following examples show how to use
com.franmontiel.persistentcookiejar.ClearableCookieJar.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: app.java From ClassSchedule with Apache License 2.0 | 6 votes |
private void initOkHttp() { ClearableCookieJar cookieJar = new PersistentCookieJar(new SetCookieCache(), new SharedPrefsCookiePersistor(getApplicationContext())); Cache.instance().setCookieJar(cookieJar); OkHttpClient okHttpClient = new OkHttpClient.Builder() //.followRedirects(false) //禁制OkHttp的重定向操作,我们自己处理重定向 .followSslRedirects(false) //.cookieJar(new LocalCookieJar()) //为OkHttp设置自动携带Cookie的功能 .addInterceptor(new LoggerInterceptor("TAG")) //.cookieJar(new CookieJarImpl(new PersistentCookieStore(getBaseContext()))) //要在内存Cookie前 //.cookieJar(new CookieJarImpl(new MemoryCookieStore()))//内存Cookie .cookieJar(cookieJar) .cache(null) .build(); OkHttpUtils.initClient(okHttpClient); }
Example #2
Source File: HttpClient.java From AndroidModulePattern with Apache License 2.0 | 5 votes |
private HttpClient() { ClearableCookieJar cookieJar = new PersistentCookieJar(new SetCookieCache(), new SharedPrefsCookiePersistor(Utils.getContext())); //HttpsUtil.SSLParams sslParams = HttpsUtil.getSslSocketFactory(Utils.getContext(), R.raw.cer,STORE_PASS , STORE_ALIAS); okHttpClient = new OkHttpClient.Builder() .connectTimeout(10000L, TimeUnit.MILLISECONDS) //.sslSocketFactory(sslParams.sSLSocketFactory, sslParams.trustManager) // .hostnameVerifier(HttpsUtil.getHostnameVerifier()) .addInterceptor(new LoggerInterceptor(null, true)) .cookieJar(cookieJar) .build(); }
Example #3
Source File: MyApplication.java From MyOkHttp with Apache License 2.0 | 5 votes |
@Override public void onCreate() { super.onCreate(); mInstance = this; //持久化存储cookie ClearableCookieJar cookieJar = new PersistentCookieJar(new SetCookieCache(), new SharedPrefsCookiePersistor(getApplicationContext())); //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(cookieJar) //设置开启cookie .addInterceptor(logging) //设置开启log .build(); mMyOkHttp = new MyOkHttp(okHttpClient); //默认 // mMyOkHttp = new MyOkHttp(); mDownloadMgr = (DownloadMgr) new DownloadMgr.Builder() .myOkHttp(mMyOkHttp) .maxDownloadIngNum(5) //设置最大同时下载数量(不设置默认5) .saveProgressBytes(50 * 1204) //设置每50kb触发一次saveProgress保存进度 (不能在onProgress每次都保存 过于频繁) 不设置默认50kb .build(); mDownloadMgr.resumeTasks(); //恢复本地所有未完成的任务 }
Example #4
Source File: RetrofitFactory.java From Toutiao with Apache License 2.0 | 5 votes |
@NonNull public static Retrofit getRetrofit() { if (retrofit == null) { synchronized (RetrofitFactory.class) { if (retrofit == null) { // 指定缓存路径,缓存大小 50Mb Cache cache = new Cache(new File(InitApp.AppContext.getCacheDir(), "HttpCache"), 1024 * 1024 * 50); // Cookie 持久化 ClearableCookieJar cookieJar = new PersistentCookieJar(new SetCookieCache(), new SharedPrefsCookiePersistor(InitApp.AppContext)); OkHttpClient.Builder builder = new OkHttpClient.Builder() .cookieJar(cookieJar) .cache(cache) .addInterceptor(cacheControlInterceptor) .connectTimeout(10, TimeUnit.SECONDS) .readTimeout(15, TimeUnit.SECONDS) .writeTimeout(15, TimeUnit.SECONDS) .retryOnConnectionFailure(true); // Log 拦截器 if (BuildConfig.DEBUG) { builder = SdkManager.initInterceptor(builder); } retrofit = new Retrofit.Builder() .baseUrl(INewsApi.HOST) .client(builder.build()) .addConverterFactory(GsonConverterFactory.create()) .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) .build(); } } } return retrofit; }
Example #5
Source File: MyApplication.java From okhttputils with Apache License 2.0 | 5 votes |
@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); }
Example #6
Source File: Cache.java From ClassSchedule with Apache License 2.0 | 4 votes |
public ClearableCookieJar getCookieJar() { return cookieJar; }
Example #7
Source File: Cache.java From ClassSchedule with Apache License 2.0 | 4 votes |
public Cache setCookieJar(ClearableCookieJar cookieJar) { this.cookieJar = cookieJar; return this; }
Example #8
Source File: NetManager.java From Aria with Apache License 2.0 | 4 votes |
public ClearableCookieJar getCookieJar() { return mCookieJar; }