2016-04-27 26 views
10

我在執行應用程序上的同步時遇到了此錯誤。主要的問題是相同的代碼適用於Android 6.0.1設備,但4.4.2設備上,我得到這個錯誤:javax.net.ssl.SSLException:4.4.2設備上的對等關閉的連接(適用於6.0.1)

javax.net.ssl.SSLException: Connection closed by peer 
at com.android.org.conscrypt.NativeCrypto.SSL_do_handshake(Native Method) 
at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:406) 
at okhttp3.internal.io.RealConnection.connectTls(RealConnection.java:188) 
at okhttp3.internal.io.RealConnection.connectSocket(RealConnection.java:145) 
at okhttp3.internal.io.RealConnection.connect(RealConnection.java:108) 
at okhttp3.internal.http.StreamAllocation.findConnection(StreamAllocation.java:188) 
at okhttp3.internal.http.StreamAllocation.findHealthyConnection(StreamAllocation.java:127) 
at okhttp3.internal.http.StreamAllocation.newStream(StreamAllocation.java:97) 
at okhttp3.internal.http.HttpEngine.connect(HttpEngine.java:289) 
at okhttp3.internal.http.HttpEngine.sendRequest(HttpEngine.java:241) 
at okhttp3.RealCall.getResponse(RealCall.java:240) 
at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:198) 
at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:203) 
at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:187) 
at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:160) 
at okhttp3.RealCall.access$100(RealCall.java:30) 
at okhttp3.RealCall$AsyncCall.execute(RealCall.java:127) 
at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:33) 
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) 
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) 
at java.lang.Thread.run(Thread.java:841) 

在那裏我無法從服務器請求數據。

如果您需要更多數據,請隨時詢問。謝謝。

+1

看看答案提供[這裏](http://stackoverflow.com/a/ 33567745/3202633)作者:Robert – am110787

+0

謝謝,這引導我去解決問題! – robigroza

回答

4

這裏的關鍵是強制TLS 1.2協議,根據this這裏的鏈接。

只有我需要在這裏正確的做法是直接強制TLS 1.2協議,是這樣的:

private class NoSSLv3SSLSocket extends DelegateSSLSocket { 

    private NoSSLv3SSLSocket(SSLSocket delegate) { 
     super(delegate); 
    } 

    @Override 
    public void setEnabledProtocols(String[] protocols) { 
     super.setEnabledProtocols(new String[]{"TLSv1.2"}); // force to use only TLSv1.2 here 
    } 
} 
+0

@DavidCheung隨意張貼您自己的答案。 – Michael

相關問題