javax.net.ssl.SSLException: Unable to parse TLS packet header
at com.android.org.conscrypt.ConscryptEngine.unwrap(ConscryptEngine.java:807)
at com.android.org.conscrypt.ConscryptEngine.unwrap(ConscryptEngine.java:747)
at com.android.org.conscrypt.ConscryptEngine.unwrap(ConscryptEngine.java:712)
at com.android.org.conscrypt.ConscryptEngineSocket$SSLInputStream.processDataFromSocket(ConscryptEngineSocket.java:858)
看到SSLException,心里第一个想法:简单,肯定是HTTPS协议没有增加SSL校验。
private SSLSocketFactory createSSLSocketFactory() {
SSLSocketFactory ssfFactory = null;
try {
SSLContext sc = SSLContext.getInstance("TLS");
sc.init(null, new TrustManager[]{mMyTrustManager}, new SecureRandom());
ssfFactory = sc.getSocketFactory();
} catch (Exception ignored) {
ignored.printStackTrace();
}
return ssfFactory;
}
//实现X509TrustManager接口
public class MyTrustManager 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 new X509Certificate[0];
}
}
new OkHttpClient.Builder() .connectTimeout(50000, TimeUnit.MILLISECONDS) .readTimeout(50000, TimeUnit.MILLISECONDS) .writeTimeout(50000, TimeUnit.MILLISECONDS) .sslSocketFactory(createSSLSocketFactory(), new MyTrustManager()) .addInterceptor(new SameRequestFilterInterceptor()) .retryOnConnectionFailure(true).build();
运行,还是报错Unable to parse TLS packet header。
见鬼了,切换到正式环境就没有问题,难道是后台的锅?【别管是不是,先把锅抛出去!】
灵光一闪,SSL是HTTPS引起的,询问后台新环境是HTTP还是HTTPS。得到结果是http。
–—————————————————撒花庆祝———————————————————
原文地址:https://blog.csdn.net/x158454996/article/details/128201552
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若转载,请注明出处:http://www.7code.cn/show_43320.html
如若内容造成侵权/违法违规/事实不符,请联系代码007邮箱:suwngjj01@126.com进行投诉反馈,一经查实,立即删除!