我在最新的android版本9.0上遇到错误
从Google lib在startHandshake引发错误
我用来发出请求的代码如下:
localHttpsURLConnection = (HttpsURLConnection) new URL(url).openConnection();
localHttpsURLConnection.setReadTimeout(15000);
localHttpsURLConnection.setConnectTimeout(15000);
localHttpsURLConnection.setRequestMethod("POST");
localHttpsURLConnection.setDoInput(true);
localHttpsURLConnection.setDoOutput(true);
localHttpsURLConnection.setUseCaches(false);
localHttpsURLConnection.setRequestProperty("Content-Type", "application/json");
localHttpsURLConnection.setRequestProperty("charset", "utf-8");
String str2 = getMeta();
localHttpsURLConnection.setRequestProperty("meta" + str2, str2);
localHttpsURLConnection.connect();
这有时工作正常,但有时会出现如下堆栈跟踪错误:
javax.net.ssl.SSLHandshakeException: Handshake failed
at com.google.android.gms.org.conscrypt.ConscryptFileDescriptorSocket.startHandshake(:com.google.android.gms@17785037@17.7.85 (100400-253824076):35)
at com.android.okhttp.internal.io.RealConnection.connectTls(RealConnection.java:1480)
at com.android.okhttp.internal.io.RealConnection.connectSocket(RealConnection.java:1424)
at com.android.okhttp.internal.io.RealConnection.connect(RealConnection.java:1368)
at com.android.okhttp.internal.http.StreamAllocation.findConnection(StreamAllocation.java:219)
at com.android.okhttp.internal.http.StreamAllocation.findHealthyConnection(StreamAllocation.java:142)
at com.android.okhttp.internal.http.StreamAllocation.newStream(StreamAllocation.java:104)
at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:392)
at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:325)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:470)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:127)
at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.connect(DelegatingHttpsURLConnection.java:89)
at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:26)
at android.os.AsyncTask$2.call(AsyncTask.java:333)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:764)
Caused by: javax.net.ssl.SSLProtocolException: SSL handshake aborted: ssl=0x79f165f848: Failure in SSL library, usually a protocol error
error:10000092:SSL routines:OPENSSL_internal:ENCRYPTED_LENGTH_TOO_LONG (third_party/openssl/boringssl/src/ssl/tls_record.cc:249 0x79d0ae8b9f:0x00000000)
at com.google.android.gms.org.conscrypt.NativeCrypto.SSL_do_handshake(Native Method)
at com.google.android.gms.org.conscrypt.NativeSsl.doHandshake(:com.google.android.gms@17785037@17.7.85 (100400-253824076):7)
at com.google.android.gms.org.conscrypt.ConscryptFileDescriptorSocket.startHandshake(:com.google.android.gms@17785037@17.7.85 (100400-253824076):14)
这主要是重点
由以下原因引起:javax.net.ssl.SSLProtocolException:SSL握手中止:ssl = 0x79f165f848:SSL库失败,通常是协议错误 错误:10000092:SSL例程:OPENSSL_internal:ENCRYPTED_LENGTH_TOO_LONG