打开连接失败:javax.net.ssl.SSLException:无法识别的 SSL 消息,纯文本连接?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37004179/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Open connection failed: javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?
提问by SUNNY
I have created a a rest mockservice using SOAP UI. And I am trying to connect it from my java class. But It is failing with error
我使用 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)
I am not sure where I am going wrong.
我不确定我哪里出错了。
Below is the code -
下面是代码——
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();
And The URL I am trying to connect is - http://localhost:8089
我尝试连接的 URL 是 - http://localhost:8089
回答by OttavioMonzione
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();
回答by SkyWalker
If you want to use HTTPSthen
如果你想使用HTTPS,那么
The HTTPS (HTTP over SSL) protocol handler has its own set of properties:
https.proxyHost https.proxyPort
As you probably guessed these work in the exact same manner as their http counterparts, so we won't go into much detail except to mention that the default port number, this time, is 443 and that for the "non proxy hosts" list, the HTTPS protocol handler will use the same as the http handler (i.e. http.nonProxyHosts).
HTTPS(基于 SSL 的 HTTP)协议处理程序有自己的一组属性:
https.proxyHost https.proxyPort
正如您可能猜到的,它们的工作方式与它们的 http 对应项完全相同,因此我们不会详细介绍,除了提及这次的默认端口号是 443 以及“非代理主机”列表的端口号, HTTPS 协议处理程序将使用与 http 处理程序相同的方式(即 http.nonProxyHosts)。
Resource Link:
资源链接:
Java Networking and Proxies for HTTPS
Solution-1:
解决方案 1:
Add the following to the JAVA_OPTS
environment variable:
将以下内容添加到JAVA_OPTS
环境变量中:
-Djsse.enableSNIExtension=false
Restartyour Crowd instance.
重启你的 Crowd 实例。
Resource Link:
资源链接:
Solution-2:
解决方案 2:
I think this is due to the connection established with the client machine is not secure. It is due to the fact that you are talking to an HTTP server, not an HTTPS server. Probably you didn't use the correct port number for HTTPS.
我认为这是由于与客户端机器建立的连接不安全。这是因为您正在与 HTTP 服务器对话,而不是 HTTPS 服务器。可能您没有为 HTTPS 使用正确的端口号。
Credit goes to @EJP
Resource Link:
资源链接:
Unrecognized SSL message, plaintext connection? Exception
Solution-3:
解决方案 3:
If you use SMTP domain name, then mail.smtp.socketFactory.fallback
properites need to be true.
如果您使用 SMTP 域名,则mail.smtp.socketFactory.fallback
属性需要为真。
props.put("mail.smtp.socketFactory.fallback", "true"); // Make it true
You can go through this link also: javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?