com.zhy.http.okhttp.log.LoggerInterceptor Java Examples

The following examples show how to use com.zhy.http.okhttp.log.LoggerInterceptor. 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 vote down vote up
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: MyApplication.java    From OpenEyes with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();
    Fresco.initialize(this);
    OkHttpClient okHttpClient = new OkHttpClient.Builder()
            .connectionSpecs(Arrays.asList(
                    ConnectionSpec.MODERN_TLS,
                    ConnectionSpec.COMPATIBLE_TLS,
                    ConnectionSpec.CLEARTEXT))
            .addInterceptor(new LoggerInterceptor("==http"))
            .connectTimeout(10000L, TimeUnit.MILLISECONDS)
            .readTimeout(10000L, TimeUnit.MILLISECONDS)
            .build();

    OkHttpUtils.initClient(okHttpClient);
}
 
Example #3
Source File: MyApplication.java    From XBanner with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();
    ViewTarget.setTagId(R.id.glide_tag);
    //Fresco初始化
    Fresco.initialize(this);
    OkHttpClient okHttpClient = new OkHttpClient.Builder()
                .addInterceptor(new LoggerInterceptor("Xbanner"))
            .connectTimeout(10000L, TimeUnit.MILLISECONDS)
            .readTimeout(10000L, TimeUnit.MILLISECONDS)
            .build();
    OkHttpUtils.initClient(okHttpClient);
    Utils.init(this);
}
 
Example #4
Source File: MyApplication.java    From okhttputils with Apache License 2.0 5 votes vote down vote up
@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);

    }