默认添加支持所有证书

2016-12-28  本文已影响19人  路途等待

<pre>
OkHttpClient.Builder mBuilder=mBuilder = new OkHttpClient.Builder();
mBuilder.sslSocketFactory(createSSLSocketFactory());
mBuilder.hostnameVerifier(new TrustAllHostnameVerifier());
mBuilder.build();
/**

private static class TrustAllManager implements X509TrustManager {
@Override
public void checkClientTrusted(X509Certificate[] chain, String authType)
throws CertificateException {
}

@Override
public void checkServerTrusted(X509Certificate[] chain, String authType)

        throws CertificateException {
}

@Override
public X509Certificate[] getAcceptedIssuers() {
    return null;//这里可能会报空指针  可以改成return new X509Certificate[0];
}

}

private static class TrustAllHostnameVerifier implements HostnameVerifier {
@Override
public boolean verify(String hostname, SSLSession session) {
return true;
}
}
</pre>

上一篇下一篇

猜你喜欢

热点阅读