【问题标题】:javax.net.ssl.SSLPeerUnverifiedException: No peer certificate on HttpClient but works fine with HttpUrlConnectionjavax.net.ssl.SSLPeerUnverifiedException:HttpClient 上没有对等证书,但与 HttpUrlConnection 一起工作正常
【发布时间】:2018-08-30 04:00:18
【问题描述】:

以前,我使用 HttpClient 进行 http post 请求,并且工作正常,直到我相信服务器团队进行了一些更改。然后我一直在 javax.net.ssl.SSLPeerUnverifiedException:无对等证书异常。

然后,经过一番摸索,我尝试了 HttpUrlConnection,它工作正常,但我仍然无法弄清楚为什么我在使用 HttpClient 时遇到了这个异常。

之前的代码是:

public String postDataAndGetStringResponse( List<NameValuePair> nameValuePairs ) {
        HttpClient client = new DefaultHttpClient();
        HttpPost post = new HttpPost( link );

        try {

            post.setEntity(new UrlEncodedFormEntity(nameValuePairs));

            HttpResponse response = client.execute(post);

            InputStream is = response.getEntity().getContent();

            String result = "";

            if (is != null) {
                BufferedReader reader = new BufferedReader(
                        new InputStreamReader(is));

                String l = "";
                while ((l = reader.readLine()) != null) {
                    result += l;
                }

                reader.close();
            }

            is.close();

            return result;
        } catch (Exception e) {
            Logger.printStackTrace(e);
            return ServerUnrechable;
        }


    }

我确实使用https://www.sslshopper.com 检查了服务器,并且所有内容都已勾选,如果有人能告诉我这个问题的原因,那将非常有帮助。

【问题讨论】:

    标签: android ssl androidhttpclient


    【解决方案1】:

    最可能的原因之一是您现在尝试使用的服务器依赖于服务器名称指示。

    SNI 支持已添加到 Android 中的 HttpsURLConnection,但未添加到捆绑的 Apache HTTP 客户端(现已弃用/删除)。详情请见this related question

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-14
      • 2020-09-01
      • 2015-06-20
      • 2015-03-04
      相关资源
      最近更新 更多