javax.net.ssl.SSLHandshakeException: Connection closed by peer at com.android.org.conscrypt.NativeCrypto.SSL_do_handshake(Native Method)

前端 未结 3 1418
天涯浪人
天涯浪人 2021-02-02 15:27

before api level 24 my code is working fine but it is giving me error on api level 24( 7.0 Nougat). I am not getting what\'s going wrong with my code.

First Approach i

相关标签:
3条回答
  • 2021-02-02 16:00

    Make sure that you have set TLS enabled from the server side.

    0 讨论(0)
  • 2021-02-02 16:09

    Do you have used Okhttp library ? It is very good library for network calls. You can handle this exception it that also.

    I had similar issue and i have managed it with this :

    public static OkHttpClient getHttpClientForFile() {
            ConnectionSpec spec = new ConnectionSpec.Builder(ConnectionSpec.MODERN_TLS)
                    .tlsVersions(TlsVersion.TLS_1_0)
                    .cipherSuites(
                            CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
                            CipherSuite.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
                            CipherSuite.TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
                            CipherSuite.TLS_DHE_RSA_WITH_AES_128_CBC_SHA,
                            CipherSuite.TLS_RSA_WITH_AES_128_CBC_SHA,
                            CipherSuite.TLS_RSA_WITH_3DES_EDE_CBC_SHA)
                    .build();
            return new OkHttpClient.Builder()
                    .connectTimeout(2, TimeUnit.MINUTES)
                    .writeTimeout(2, TimeUnit.MINUTES)
                    .readTimeout(3, TimeUnit.MINUTES)
                    .connectionSpecs(Collections.singletonList(spec))
                    .protocols(Arrays.asList(Protocol.HTTP_1_1))
                    .build();
        }
    

    I don't know whether it is good or not, but it is working for me.

    The class you have used SSLSocketFactory may produce error after publishing app on play store or play store may give you warning to change your code.

    You can find Okhttp library from https://github.com/square/okhttp.

    0 讨论(0)
  • 2021-02-02 16:23

    I have faced the same issue, same javax.net.ssl.SSLHandshakeException is throwing at the time of API call.

    but in my case, the following was the issue

    my device was connected to the wifi but wifi router was not having the internet connection and then the exception was thrown

    0 讨论(0)
提交回复
热议问题