1 回答
TA贡献1810条经验 获得超4个赞
事实证明,问题是由在 okhttp3 构建器方法中调用 NullPointerException 引起的。确切的代码在这里:
Caused by: java.lang.NullPointerException: Attempt to get length of null array
at okhttp3.internal.tls.BasicTrustRootIndex.<init>(BasicTrustRootIndex.java:32)
at okhttp3.internal.platform.Platform.buildTrustRootIndex(Platform.java:288)
at okhttp3.internal.platform.AndroidPlatform.buildTrustRootIndex(AndroidPlatform.java:280)
at okhttp3.internal.platform.Platform.buildCertificateChainCleaner(Platform.java:172)
at okhttp3.internal.platform.AndroidPlatform.buildCertificateChainCleaner(AndroidPlatform.java:230)
at okhttp3.internal.tls.CertificateChainCleaner.get(CertificateChainCleaner.java:41)
at okhttp3.OkHttpClient$Builder.sslSocketFactory(OkHttpClient.java:694)
这个问题的原因是我在 Stackoverflow(此处为IE)上遵循了大量示例,这些示例告诉您使用该行构建 x509 TrustManager return null;。
解决方法是简单地更改一行:
X509TrustManager trustManager = new X509TrustManager() {
public void checkClientTrusted(X509Certificate[] xcs, String string)
throws CertificateException {}
public void checkServerTrusted(X509Certificate[] xcs, String string)
throws CertificateException {}
public X509Certificate[] getAcceptedIssuers() {
//Here
return new X509Certificate[]{};
}
};
.
.
.
这解决了这个问题。
添加回答
举报