Java Code Examples for com.zhy.http.okhttp.OkHttpUtils#initClient()
The following examples show how to use
com.zhy.http.okhttp.OkHttpUtils#initClient() .
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 Socket.io-FLSocketIM-Android with MIT License | 6 votes |
private void initOkHttpUtil () { CookieJarImpl cookieJar = new CookieJarImpl(new PersistentCookieStore(getApplicationContext())); OkHttpClient client = new OkHttpClient.Builder() .connectionPool(new ConnectionPool(5, 5, TimeUnit.MINUTES)) .addInterceptor(new Interceptor() { @Override public Response intercept(Chain chain) throws IOException { Request request = chain.request(); request = request.newBuilder().addHeader("Connection", "keep-alive").build(); return chain.proceed(request); } }) .connectTimeout(10, TimeUnit.SECONDS) .readTimeout(30, TimeUnit.SECONDS) .writeTimeout(60, TimeUnit.SECONDS) .cookieJar(cookieJar) .build(); OkHttpUtils.initClient(client); }
Example 2
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 3
Source File: OklaClient.java From iMoney with Apache License 2.0 | 6 votes |
/** * initialize okhttp client config * * @param context */ private void initOkhttpClient(Context context) { if (context == null) return; OkHttpClient okHttpClient = new OkHttpClient.Builder() .connectTimeout(10000L, TimeUnit.MILLISECONDS) .readTimeout(10000L, TimeUnit.MILLISECONDS) // .dns(OkHttpDns.getInstance(context)) // .hostnameVerifier(new HostnameVerifier() { // @Override // public boolean verify(String hostname, SSLSession session) { // return hostname.contains("domain.com");// 替换为自己api的域名 // } // }) // .sslSocketFactory(getSSLSocketFactory()) .build(); OkHttpUtils.initClient(okHttpClient); }
Example 4
Source File: MyApplication.java From OpenEyes with Apache License 2.0 | 6 votes |
@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 5
Source File: App.java From LiuAGeAndroid with MIT License | 5 votes |
@Override public void onCreate() { super.onCreate(); app = this; // 存放所有activity的集合 mActivityList = new ArrayList<>(); // 初始化app异常处理器 - 打包的时候开启 // CrashHandler handler = CrashHandler.getInstance(); // handler.init(getApplicationContext()); // 初始化OkHttpUtils OkHttpClient okHttpClient = new OkHttpClient.Builder() .connectTimeout(10000L, TimeUnit.MILLISECONDS) .readTimeout(10000L, TimeUnit.MILLISECONDS) //其他配置 .build(); OkHttpUtils.initClient(okHttpClient); // 初始化Fresco ImagePipelineConfig config = ImagePipelineConfig.newBuilder(this) .setProgressiveJpegConfig(new SimpleProgressiveJpegConfig()) .build(); Fresco.initialize(this, config); // 初始化ShareSDK ShareSDK.initSDK(this); // 初始化JPush JPushInterface.setDebugMode(true); JPushInterface.init(this); // 更新用户登录状态 UserBean.updateUserInfoFromNetwork(new UserBean.OnUpdatedUserInfoListener()); }
Example 6
Source File: MyApplication.java From XBanner with Apache License 2.0 | 5 votes |
@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 7
Source File: App.java From XDroid with MIT License | 5 votes |
@Override public void onCreate() { super.onCreate(); OkHttpClient okHttpClient = new OkHttpClient.Builder() .connectTimeout(10000L, TimeUnit.MILLISECONDS) .readTimeout(10000L, TimeUnit.MILLISECONDS) //其他配置 .build(); OkHttpUtils.initClient(okHttpClient); context = getApplicationContext(); }
Example 8
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 9
Source File: AppContext.java From renrenpay-android with Apache License 2.0 | 4 votes |
@Override public void onCreate() { super.onCreate(); instance = this; configManager = ConfigManager.getInstance(); CrashReport.initCrashReport(getApplicationContext(), "7b37c18319", false); OkHttpClient okHttpClient = new OkHttpClient.Builder() .connectTimeout(10000L, TimeUnit.MILLISECONDS) .readTimeout(10000L, TimeUnit.MILLISECONDS) //其他配置 .build(); String processAppName = getAppName(android.os.Process.myPid()); // 如果APP启用了远程的service,此application:onCreate会被调用2次 // 为了防止被初始化2次,加此判断会保证SDK被初始化1次 // 默认的APP会在以包名为默认的process name下运行,如果查到的process name不是APP的process name就立即返回 if (processAppName == null || !processAppName.equalsIgnoreCase(this.getPackageName())) { // 则此application::onCreate 是被service 调用的,直接返回 return; } instance = this; // 程序崩溃时触发线程 以下用来捕获程序崩溃异常并重启应用 Thread.setDefaultUncaughtExceptionHandler(restartHandler); HookList.getInstance(); registerReceiver(new ReceiverMain(), new IntentFilter(HookBase.RECV_ACTION)); OkHttpUtils.initClient(okHttpClient); accountManager = new AccountManager(); Log.d(TAG, accountManager.toString()); int id = accountManager.getUserId(); if(id == 0) { id = configManager.getInt("id", 0); } if (accountManager.isLogined()) { User user = UserDao.findById(id); if(user != null) setUser(user); else accountManager.setLogined(false); } }
Example 10
Source File: CheckVersionService.java From POCenter with MIT License | 4 votes |
public CheckVersionService() { OkHttpUtils.initClient(UnsafeOkHttpUtils.getClient()); }
Example 11
Source File: CustomApplication.java From TestChat with Apache License 2.0 | 4 votes |
private void initOkHttp() { OkHttpUtils.initClient(new OkHttpClient.Builder().connectTimeout(10, TimeUnit.SECONDS).readTimeout(10, TimeUnit.SECONDS).build()); }