Dashingl
2016-12-26 08:33
采纳率: 0%
浏览 3.7k

Android OkHttp 请求Https服务端怎么忽略证书?

Android OkHttp 请求Https服务端怎么忽略证书,网上的方法都试过了(然并卵),现请教可行的方法(测试可行),谢谢大家

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • oyljerry 2016-12-26 09:31
     OkHttpClient.Builder builder = new OkHttpClient.Builder();
    
    builder.sslSocketFactory(sslContext.getSocketFactory(),
                        new X509TrustManager() {
                            @Override
                            public void checkClientTrusted(java.security.cert.X509Certificate[] chain, String authType) throws CertificateException {
                            }
    
                            @Override
                            public void checkServerTrusted(java.security.cert.X509Certificate[] chain, String authType) throws CertificateException {
                            }
    
                            @Override
                            public java.security.cert.X509Certificate[] getAcceptedIssuers() {
                                return new java.security.cert.X509Certificate[]{};
                            }
                        });
    
    打赏 评论
  • Antway_ 2016-12-26 14:35

    使用自定义证书并忽略验证的HTTPS连接方式
    http://blog.csdn.net/u012896330/article/details/52448024

    打赏 评论

相关推荐 更多相似问题