OKGo https配置

/**
         * 第一种加载证书
         */
        try {
            HttpsUtils.SSLParams sslParams = HttpsUtils.getSslSocketFactory(getAssets().open("wallet.cer"));
            OkHttpClient builder = new OkHttpClient.Builder()
                    .sslSocketFactory(sslParams.sSLSocketFactory, sslParams.trustManager)
                    .hostnameVerifier(new HostnameVerifier() {
                        @Override
                        public boolean verify(String hostname, SSLSession session) {
                            return true;
                        }
                    }).build();
            OkGo.getInstance().setOkHttpClient(builder);
        }catch (Exception e){
            e.printStackTrace();
        }
        /**
         * 第二种忽略证书
         */
        HttpsUtils.SSLParams sslParams = HttpsUtils.getSslSocketFactory();
        OkHttpClient builder = new OkHttpClient.Builder()
                .sslSocketFactory(sslParams.sSLSocketFactory, sslParams.trustManager)
                .hostnameVerifier(new HostnameVerifier() {
                    @Override
                    public boolean verify(String hostname, SSLSession session) {
                        return true;
                    }
                }).build();
        OkGo.getInstance().init(this).setOkHttpClient(builder);

 

posted @ 2020-05-09 11:28  青竹玉简  阅读(1364)  评论(0编辑  收藏  举报