在android 7.0牛轧糖中获取javax.net.ssl.SSLHandshakeException

时间:2016-11-15 06:03:38

标签: android-7.0-nougat

我收到错误

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

当我尝试访问HTTPS网址时。 我的代码是:

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;
    }
}

我的代码正在处理api级别23.我不知道为什么仅在Nougat(Android 7.0)中抛出此异常。

0 个答案:

没有答案