Today, I switched the environment for debugging, and a certain interface suddenly reported an error:
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)
Seeing SSLException, the first thought in my heart: simple, it must be that the HTTPS protocol has not added SSL verification.
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];
}
}
create
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();
Running, still reporting Unable to parse TLS packet header error.
Hell, there is no problem switching to the official environment. Could it be the pot in the background? [Don't worry about it, throw the pot out first! 】
With a flash of inspiration, SSL is caused by HTTPS, and asked whether the new background environment is HTTP or HTTPS. The result is http.
Sure enough, change https to http, run - success!
———————————————————Scattering flowers to celebrate ————————————————————