首页 > Web开发 > 详细

OKGo https配置

时间:2020-05-09 12:30:53      阅读:172      评论:0      收藏:0      [点我收藏+]
/**
         * 第一种加载证书
         */
        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);

 

OKGo https配置

原文:https://www.cnblogs.com/matd/p/12856210.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!