【问题标题】:SSLException: hostname in certificate didn't match: <50.19.233.255> != <*.heroku.com>SSLException:证书中的主机名不匹配:<50.19.233.255> != <*.heroku.com>
【发布时间】:2015-12-28 12:50:53
【问题描述】:

我正在尝试从 java 调用 heroku 的开发者 api,但我得到以下异常:

    Exception in thread "main" javax.net.ssl.SSLException: hostname in certificate didn't match: <50.19.233.255> != <*.heroku.com>

我的代码如下所示:

    HttpClient client = new DefaultHttpClient();
    HttpGet request = new HttpGet("https://api.heroku.com/apps");
    String token = "d6d7ea6e-6e71-4f13-b0ff-ed9ee9d56c37";
    request.addHeader("Authorization", "Bearer "+token);
    HttpResponse response = client.execute(request);

如果我用 curl 试试,效果很好:

    curl "https://api.heroku.com/apps" -H"Authorization: Bearer d6d7ea6e-6e71-4f13-b0ff-ed9ee9d56c37"

为什么 java 代码的行为与 curl 不同?

附:我知道其他人已经问过这个问题,但所有的答案,例如:

https://stackoverflow.com/a/7266768

https://stackoverflow.com/a/3904473

https://stackoverflow.com/a/25356821

建议我应该覆盖证书主机名检查,这肯定会失败(当然还没有准备好生产)?

【问题讨论】:

    标签: java ssl ssl-certificate apache-httpclient-4.x


    【解决方案1】:

    Apache HttpClient resolving domain to IP address and not matching certificate 中描述了此问题。 这似乎是您正在使用的 HTTPClient 版本中的一个错误,它将目标 IP 而不是目标主机名与主题证书进行比较。请改用固定版本的 HTTPClient。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-16
      • 1970-01-01
      • 2018-06-18
      • 2013-10-18
      • 2016-08-09
      • 1970-01-01
      相关资源
      最近更新 更多