3

I am getting an error

javax.net.ssl.SSLHandshakeException: Connection closed by peer

when i am trying to access a HTTPS url. my code is:

private void executeHTTRequestVerifyingLogin(String userid, String pwd, String key) throws Exception {
    String strReturn = "";
    BufferedReader in = null;
    HttpClient hc = CUtils.getNewHttpClient();
    HttpPost hp = new HttpPost(CGlobalVariables.VERIFYING_LOGIN);
    try {
        hp.setEntity(new UrlEncodedFormEntity(getNameValuePairs_Login(userid, pwd, key), HTTP.UTF_8));
        HttpResponse response = hc.execute(hp);
        in = new BufferedReader(new InputStreamReader(response.getEntity()
                .getContent()));
        StringBuffer sb = new StringBuffer("");
        String data = "";
        while ((data = in.readLine()) != null)
            sb.append(data);
        in.close();
        setVerifyingLoginValue(sb.toString());
    } catch (Exception e) {
        throw e;
    }
}

My code is working upto api level 23. I don't know why this exception is thrown in Nougat(Android 7.0) only.

chandan kumar
  • 190
  • 1
  • 15
  • SSL handling changed significantly in Android 7.0 with the introduction of [network security configuration](https://developer.android.com/training/articles/security-config.html). Probably they changed up the mix of supported root certificate authorities as well. Also, if you are still using the built-in HttpClient, there could be new and exciting bugs in there, since that is no longer being maintained. – CommonsWare Nov 15 '16 at 14:12
  • when i am using Retrofit to hit the server it says `retrofit.RetrofitError: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.` how to resolve the certificate issue. – chandan kumar Nov 16 '16 at 09:32
  • The SSL certificate provided by your server does not have a "trust anchor" (e.g., root certificate) recognized by Android. Talk to whoever maintains the server and figure out what they are using for an SSL certificate. – CommonsWare Nov 16 '16 at 11:53
  • 1
    please try this answer http://stackoverflow.com/questions/39215229/how-to-get-charles-proxy-work-with-android-7-nougat – Mahtab Nov 28 '16 at 06:37

0 Answers0