无法识别的SSL消息,明文连接? 例外

我有一个java complied包来与networking上的https服务器通话。 运行编译会导致以下exception:

javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection? at com.sun.net.ssl.internal.ssl.InputRecord.handleUnknownRecord(Unknown Source) at com.sun.net.ssl.internal.ssl.InputRecord.read(Unknown Source) at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(Unknown Source) at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source) at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(Unknown Source) at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(Unknown Source) at sun.net.www.protocol.https.HttpsClient.afterConnect(Unknown Source) at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(Unknown Source) at sun.net.www.protocol.https.HttpsURLConnectionImpl.connect(Unknown Source) 

我想这是由于与客户机build立的连接不安全。 有什么办法来configuration本地机器或端口以连接到远程https服务器?

我想这是由于与客户机build立的连接不安全。

这是因为您正在与HTTP服务器通信,而不是HTTPS服务器。 可能您没有使用HTTPS的正确端口号。

 javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection? 

你应该有一个本地的SMTP域名,将联系邮件服务器,并build立一个新的连接,以及你应该改变你的程序下面的SSL属性

 javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection props.put("mail.smtp.socketFactory.fallback", "true"); // Should be true 

在通过代理执行POST请求之前,当我忘记login到公司防火墙时,我收到了相同的错误消息。

我得到了同样的错误。 这是因为我使用http访问https端口。当我将http更改为https时,问题得以解决。

我面临来自Jdevelop 11.1.1.7 IDE中构build的Java应用程序的相同问题。 我通过取消选中使用代理窗体项目属性来解决问题。

您可以在下面find它:项目属性 – >(从左边的Panle)运行/debugging/configuration文件 – >点击(编辑)从右侧面板 – >左侧面板中的工具设置 – >取消选中(使用代理)选项。

它现在为我工作,我已经改变了我的谷歌帐户的设置如下:

  System.out.println("Start"); final String username = "myemail@gmail.com"; final String password = "************"; Properties props = new Properties(); props.put("mail.smtp.auth", "true"); props.put("mail.smtp.host", "smtp.gmail.com"); props.put("mail.smtp.port", "465"); props.put("mail.transport.protocol", "smtp"); props.put("mail.smtp.starttls.enable", "true"); props.put("mail.smtp.starttls.enable", "true"); props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory"); Session session = Session.getInstance(props, new javax.mail.Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(username, password); } }); try { Transport transport=session.getTransport(); Message message = new MimeMessage(session); message.setFrom(new InternetAddress("myemail@gmail.com"));//formBean.getString("fromEmail") message.setRecipients(Message.RecipientType.TO,InternetAddress.parse("myemail@gmail.com")); message.setSubject("subject");//formBean.getString( message.setText("mailBody"); transport.connect(); transport.send(message, InternetAddress.parse("myemail@gmail.com"));//(message); System.out.println("Done"); } catch (MessagingException e) { System.out.println("e="+e); e.printStackTrace(); throw new RuntimeException(e); } 

虽然我在同一个post的这个链接中运行程序时启用了SSL和TSL。 我花了很多时间,但是我意识到并find了这个链接。 并完成2以下步骤,并在谷歌设置控制。 :

  • 禁用两步validation(密码和OTP)

  • 启用允许访问不太安全的应用程序( 允许安全性较低的应用程序:开启。

现在我可以使用上面的程序发送邮件了。

正如EJP所说,这是一个显示的消息,因为对非https协议的调用。 如果您确定它是HTTPS,请检查您的绕过代理设置,并在您的web服务主机url添加到绕过代理列表

添加这个答案,以后可能会有帮助。

我不得不强制jvm使用IPv4堆栈来解决错误。 我的应用程序曾经在公司networking中工作,但是在家中连接时,它也有同样的例外。 没有涉及代理。 添加了jvm参数-Djava.net.preferIPv4Stack=true ,所有的https请求都正常运行。

如果连接是FTPStesting:

FTPSClient ftpClient = new FTPSClient(protocol,false);

protocol = TLS,SSL和false = isImplicit。

另一个原因可能是“访问被拒绝”,也许你不能访问URI并收到内部networking访问阻塞响应页面。 如果您不确定您的应用程序区域是否需要防火墙规则,则尝试从terminal,命令行进行连接。 对于GNU / Linux或Unix,你可以尝试像这样的命令运行,看到结果来自阻塞规则或真正的远程地址: echo | nc -v yazilimcity.net 443 echo | nc -v yazilimcity.net 443

也许你的默authentication书已经过期。 通过pipe理控制台进行更新转到“安全> SSL证书和密钥pipe理>密钥存储和证书> NodeDefaultKeyStore>个人证书”select“默认”别名,然后点击“更新”,然后重新启动WAS。

如果您正在Java 6或更低版本的命令行上运行Java进程,则添加此开关可解决上述问题:

-Dhttps.protocols = “使用TLSv1”