java - SSLException : hostname in certificate didn't match: <50. 19.233.255> != <*.heroku.com>

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

我试图从 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

建议我应该覆盖证书主机名检查,这肯定违背了要点(当然不是生产就绪)?

最佳答案

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

关于java - SSLException : hostname in certificate didn't match: <50. 19.233.255> != <*.heroku.com>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34493872/

相关文章:

ssl - SOAPUI 和 SSL_VERIFY_PEER

python - 使用 python api 和私钥访问谷歌云存储 - Bad Handshake

node.js - 错误 : unable to verify the first certificate in nodejs

java - Roo 或 Grails(同一公司,类似产品)

java - 在线程失败和异常处理时停止 ExecutorService

java - Selenium RC 中的 XPath 或 CSS 与 Java 不起作用

ssl - 解析 SSL 证书问题

java - 如何将外部 jar 添加到 hadoop 作业?

html - 带有用户名和密码的 HTML 文件上的 SSL 和 FTP url

php - HTTP ://wrapper is disabled in the server configuration by allow_url_fopen=0 in