okhttp tls 1.2 android 4进行了改造

时间:2019-06-23 10:06:19

标签: retrofit retrofit2 okhttp okhttp3

我是新来的。我正在尝试使用okhttp进行改造。我希望在android 4和5上支持tls 1.2。我发现此解决方案可能会起作用。

https://github.com/square/okhttp/issues/2372#issuecomment-244807676

我创建了Tls12SocketFactory.java文件,下一步该怎么做?

但是我不知道如何在代码中正确实现这一点。谁能帮我在okhttp和改造代码中实现这一点?谁能修改我的代码?

public static Retrofit getClient() {
    if (retrofit==null) {
        OkHttpClient okHttpClient = new OkHttpClient().newBuilder()
                .addInterceptor( provideHttpLoggingInterceptor() )
                .addInterceptor( provideOfflineCacheInterceptor() )
                .addNetworkInterceptor( provideCacheInterceptor() )
                .cache( provideCache() )
                .connectTimeout(60, TimeUnit.SECONDS)
                .readTimeout(60, TimeUnit.SECONDS)
                .writeTimeout(60, TimeUnit.SECONDS)
                .build();

        OkHttp3Downloader okHttp3Downloader = new OkHttp3Downloader(okHttpClient);
        Picasso picasso = new Picasso.Builder(App.getInstance())
                .downloader(okHttp3Downloader)
                .build();
        Picasso.setSingletonInstance(picasso);

        retrofit = new Retrofit.Builder()
                .baseUrl(Config.BASE_URL)
                .client(okHttpClient)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }
    return retrofit;
}

0 个答案:

没有答案