Android 7.0 : 'javax.net.ssl.SSLHandshakeException: Connection closed by peer

前端 未结 2 1670
礼貌的吻别
礼貌的吻别 2021-01-14 11:30

When I am trying to access a \'https\' web service from my app , it is giving a \'javax.net.ssl.SSLHandshakeException: Connection closed by peer\' error. Th

2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-14 12:20

    try use this code, it work for me :

     private static void initializeSSLContext(Context mContext){
        try {
            SSLContext.getInstance("TLSv1.2");
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        try {
            ProviderInstaller.installIfNeeded(mContext.getApplicationContext());
        } catch (GooglePlayServicesRepairableException e) {
            e.printStackTrace();
        } catch (GooglePlayServicesNotAvailableException e) {
            e.printStackTrace();
        }
    }
    

    and don't forget to usr google security library :

      compile 'com.google.android.gms:play-services-safetynet:11.6.2'
    

提交回复
热议问题