【问题标题】:Open connection failed: javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection? [duplicate]打开连接失败:javax.net.ssl.SSLException:无法识别的 SSL 消息,明文连接? [复制]
【发布时间】:2016-08-28 12:02:01
【问题描述】:

我使用 SOAP UI 创建了一个休息模拟服务。 我正在尝试从我的 java 类中连接它。但它失败并出现错误

Open connection failed: javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?
sun.security.ssl.InputRecord.handleUnknownRecord(Unknown Source)
sun.security.ssl.InputRecord.read(Unknown Source)
sun.security.ssl.SSLSocketImpl.readRecord(Unknown Source)
sun.security.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source)

我不确定我哪里出错了。

下面是代码 -

java.net.URL url = new URL(null, address,new sun.net.www.protocol.https.Handler());
connection = (javax.net.ssl.HttpsURLConnection) url.openConnection();
connection.setDoOutput(true);
connection.setRequestProperty("Content-Type", "text/xml");
connection.setRequestMethod("GET");
connection.connect();

我尝试连接的 URL 是 - http://localhost:8089

【问题讨论】:

  • 您正在混合使用 HTTP 和 HTTPS 的东西。模拟服务是否通过 SOAP UI 通过 SSL 公开?您只需要将地址变量方案更改为 HTTPS。 SOAP UI 是否通过 HTTP 公开模拟?您必须使用 URLConnection 而不是 HttpsURLConnection
  • 不,我的 mockservice 没有通过 SSL 公开,我该怎么做?请给我建议。

标签: java ssl


【解决方案1】:
java.net.URL url = new URL("http://localhost:8089");
java.net.URLConnection connection = url.openConnection();
connection.setDoOutput(true);
connection.setRequestProperty("Content-Type", "text/xml");
connection.setRequestMethod("GET");
connection.connect();

【讨论】:

  • 这将作为 http 请求工作,但我想将其设为 https。
  • @SUNNY 然后使用正确的端口号
  • 不要简单地发布代码 sn-p,在您的答案中添加一些说明。像这样的答案经常被删除。
【解决方案2】:

如果你想使用 HTTPS 那么

HTTPS(HTTP over SSL)协议处理程序有自己的一套 属性:

https.proxyHost
https.proxyPort

正如您可能猜到的那样,它们的工作方式与它们完全相同 http对应,所以我们不会详细介绍,只提一下 这次默认端口号是 443,而“非 代理主机”列表,HTTPS 协议处理程序将使用与 http 处理程序(即 http.nonProxyHosts)。

资源链接:

Java Networking and Proxies for HTTPS

解决方案一:

将以下内容添加到JAVA_OPTS 环境变量中:

-Djsse.enableSNIExtension=false

重新启动您的 Crowd 实例。

资源链接:

https://confluence.atlassian.com/crowdkb/unrecognized-ssl-message-plaintext-connection-582877397.html

解决方案 2:

我认为这是由于与客户端计算机建立的连接不安全。 这是因为您正在与 HTTP 服务器而不是 HTTPS 服务器通信。可能您没有为 HTTPS 使用正确的端口号。

归功于@EJP

资源链接:

Unrecognized SSL message, plaintext connection? Exception

解决方案 3:

如果您使用 SMTP 域名,则 mail.smtp.socketFactory.fallback 属性需要为 true。

props.put("mail.smtp.socketFactory.fallback", "true"); // Make it true

您也可以通过此链接:javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?

【讨论】:

  • 解决方案 3 最终为我工作。
  • 我认为这是由于与客户端机器建立的连接不安全。这是因为您正在与 HTTP 服务器而不是 HTTPS 服务器通信。可能您没有为 HTTPS 使用正确的端口号。
猜你喜欢
  • 2011-06-06
  • 1970-01-01
  • 2014-08-08
  • 2016-08-04
  • 1970-01-01
  • 2016-08-09
  • 2014-02-04
  • 2011-09-25
相关资源
最近更新 更多