Java 无法识别的 SSL 消息,纯文本连接?例外

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6532273/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-16 06:42:53  来源:igfitidea点击:

Unrecognized SSL message, plaintext connection? Exception

javahttps

提问by karthi

I have a java complied package to speak with the https server on net. Running the compilation gives the following exception:

我有一个 Java 编译包来与网络上的 https 服务器通信。运行编译会出现以下异常:

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)

I think this is due to the connection established with the client machine is not secure. Is there any way to configure the local machine or ports in order to connect to the remote https server?

我认为这是由于与客户端机器建立的连接不安全。有没有办法配置本地机器或端口以连接到远程 https 服务器?

采纳答案by user207421

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 使用正确的端口号。

回答by Thobith

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

You should have a local SMTP domain name that will contact the mail server and establishes a new connection as well you should change the SSL property in your programming below

您应该有一个本地 SMTP 域名,它将联系邮件服务器并建立新的连接,您应该在下面的编程中更改 SSL 属性

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

 props.put("mail.smtp.socketFactory.fallback", "true"); // Should be true

回答by Jay

I got the same error message when I forgot to log in to the company firewall, before performing a POST request through a proxy.

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

回答by Soumyajit Swain

I got the same error. it was because I was accessing the https port using http.. The issue solved when I changed http to https.

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

回答by Mithat Bozkurt

Maybe your default cerficate has expired. to renew it through admin console go "Security >SSL certificate and key management > Key stores and certificates > NodeDefaultKeyStore > Personal certificates" select the "default" alias and click on "renew" after then restart WAS.

也许您的默认证书已过期。要通过管理控制台更新它,请转到“安全 > SSL 证书和密钥管理 > 密钥库和证书 > NodeDefaultKeyStore > 个人证书”,选择“默认”别名,然后单击“更新”,然后重新启动 WAS。

回答by Salman

I face the same issue from Java application built in Jdevelopr 11.1.1.7 IDE. I solved the issue by unchecking the use of proxy form Project properties.

我在 Jdevelopr 11.1.1.7 IDE 中构建的 Java 应用程序中遇到了同样的问题。我通过取消选中代理表单项目属性的使用解决了这个问题。

You can find it in the following: Project Properties -> (from left panle )Run/Debug/Profile ->Click (edit) form the right panel -> Tool Setting from the left panel -> uncheck (Use Proxy) option.

您可以在以下位置找到它:项目属性 ->(从左侧面板)运行/调试/配置文件 ->单击(编辑)右侧面板 -> 左侧面板中的工具设置 -> 取消选中(使用代理)选项。

回答by MarkL

If you're running the Java process from the command line on Java 6 or earlier, adding this switch solved the issue above for me:

如果您在 Java 6 或更早版本上从命令行运行 Java 进程,添加此开关可为我解决上述问题:

-Dhttps.protocols="TLSv1"

-Dhttps.protocols="TLSv1"

回答by Fabrizio Stellato

As EJP said, it's a message shown because of a call to a non-https protocol. If you are sure it is HTTPS, check your bypass proxy settings, and in case add your webservice host url to the bypass proxy list

正如 EJP 所说,这是由于调用非 https 协议而显示的消息。如果您确定它是 HTTPS,请检查您的绕过代理设置,以防万一将您的网络服务主机 url 添加到绕过代理列表中

回答by Laxman G

It worked for me now, I have change the setting of my google account as below:

它现在对我有用,我已经更改了我的谷歌帐户设置,如下所示:

        System.out.println("Start");
        final String username = "[email protected]";
        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("[email protected]"));//formBean.getString("fromEmail")
            message.setRecipients(Message.RecipientType.TO,InternetAddress.parse("[email protected]"));
            message.setSubject("subject");//formBean.getString(
            message.setText("mailBody");
            transport.connect();
            transport.send(message, InternetAddress.parse("[email protected]"));//(message);

            System.out.println("Done");

        } catch (MessagingException e) {
            System.out.println("e="+e);
            e.printStackTrace();
            throw new RuntimeException(e);

        }

Though I have enabled SSL and TSL while running program in this linkof same post. I spend a lot of time but than I realized and found this link. And done 2 following steps and setting control in google. :

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

  • Disable the 2-step verification (password and OTP)

  • Enabling to allow to access less secure app(Allow less secure apps: ON.)

  • 禁用两步验证(密码和一次性密码)

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

Now I am able to send mail using above program.

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

回答by basiljames

Adding this as an answer as it might help someone later.

将此添加为答案,因为它可能会在以后对某人有所帮助。

I had to force jvm to use the IPv4 stack to resolve the error. My application used to work within company network, but while connecting from home it gave the same exception. No proxy involved. Added the jvm argument -Djava.net.preferIPv4Stack=trueand all the httpsrequests were behaving normally.

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