Trust anchor for certification path not found.问题解决(关于okhttputils的BUG)

憋了3天,参照https://github.com/DeadLine837/TestHttps上的例子,与我的代码的区别,终于搞明白了

自签名,单向认证。

下面这两种写法就会报错:


1、==============================
    InputStream inputStream = getResources().getAssets().open("zhy_server.cer");
    HttpsUtils.SSLParams sslParams = HttpsUtils.getSslSocketFactory(new InputStream[]{inputStream}, null, null);

2、==============================
    InputStream ins[] = null;
    ins[0] = getAssets().open("assets/zhy_server.cer");
    HttpsUtils.SSLParams sslParams = HttpsUtils.getSslSocketFactory(ins, null, null);

 
下面这两种写法正确:
3、==============================
    HttpsUtils.SSLParams sslParams = HttpsUtils.getSslSocketFactory(new InputStream[]{new Buffer().writeUtf8(CER_12306).inputStream()}, null, null);

            
4、==============================
    HttpsUtils.SSLParams sslParams = HttpsUtils.getSslSocketFactory(new InputStream[]{getResources().getAssets().open("zhy_server.cer")}, null, null);


    用别人的东西,踩着坑也没办法,放到网上给大家参照一下吧,节省点时间

你可能感兴趣的:(Trust anchor for certification path not found.问题解决(关于okhttputils的BUG))