【问题标题】:Getting Unsupported or unrecognized SSL message; nested exception is javax.net.ssl.SSLException while calling external API获取不受支持或无法识别的 SSL 消息;调用外部 API 时嵌套异常为 javax.net.ssl.SSLException
【发布时间】:2021-02-05 15:27:43
【问题描述】:

我正在我的应用程序中调用外部 Rest 端点。但我收到以下错误:

 The response body does not contain an access token
 org.springframework.web.client.ResourceAccessException: I/O error on POST request for 
 "https://example.com/api/auth": Unsupported or unrecognized SSL message; nested exception is 
  javax.net.ssl.SSLException: Unsupported or unrecognized SSL message

在这种情况下,我找到了一篇文章如下:

Unrecognized SSL message, plaintext connection? Exception

但是,我没有发现这很有用,因为我正在与端口号为 443 的 HTTPS 服务器通信。

这是否会因为白名单而发生,我的意思是我要连接的 HTTPS 服务器端点尚未列入白名单?

【问题讨论】:

  • 如果你 curl -v https://example.com/api/auth 怎么办?

标签: java ssl https


【解决方案1】:

我也遇到过您列出的例外情况,尽管是在不同的情况下。我看到这个问题还没有答案,所以我根据对this question 的回答分享我如何修复它的经验,这帮助我意识到这个问题与https 和@987654323 有某种关系@。这个答案也可能对试图实现我在下面尝试的人有用。

我在尝试通过代理路由时尝试连接到安全端点时使用 Apache HttpClient 遇到了这种情况。

我通过扩展DefaultRoutePlanner 实现了一个自定义RoutePlanner 并实现了determineProxy 方法,如下所示:

@Override
protected HttpHost determineProxy(final HttpHost target, final HttpRequest request, final HttpContext context) {
    return new HttpHost(proxyHost, proxyPort, target.getScheme());
}

问题是目标的方案是https。通过删除方案参数,HttpHost 将自动将其设置为 http

这是工作代码:

@Override
protected HttpHost determineProxy(final HttpHost target, final HttpRequest request, final HttpContext context) {
    return new HttpHost(proxyHost, proxyPort);
}

换句话说,为了到达https 端点,我需要通过代理进行路由,其主机只是http

【讨论】:

  • 这帮助我解决了与 RedHat 的 Resteasy 客户端类似的问题。我将它配置为使用 HTTPS 代理,但我也需要为 HTTP 配置它,否则我会遇到同样的错误。
猜你喜欢
  • 1970-01-01
  • 2021-02-10
  • 2014-08-08
  • 1970-01-01
  • 2011-06-06
  • 1970-01-01
  • 2016-08-04
  • 2017-09-09
  • 2020-10-30
相关资源
最近更新 更多