我有一个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)

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


当前回答

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

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

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

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

其他回答

我也遇到了同样的问题,通过在系统属性中设置“proxyUser”和“proxyPassword”来解决。

System.setProperty("http.proxyUser", PROXY_USER);
System.setProperty("http.proxyPassword", PROXY_PASSWORD);

连同“proxyHost”和“proxyPort”

System.setProperty("http.proxyHost", PROXY_ADDRESS);
System.setProperty("http.proxyPort", PROXY_PORT);

希望它能起作用。

我有类似的错误使用骆驼邮件组件发送电子邮件的gmail smtp。

解决方案从TLS端口(587)更改为SSL端口(465),如下所示:

<route id="sendMail">
  <from uri="jason:toEmail"/>
  <convertBodyTo type="java.lang.String"/>
  <setHeader headerName="Subject"><constant>Something</constant></setHeader>
  <to uri="smtps://smtp.gmail.com:465?username=myemail@gmail.com&amp;password=mypw&amp;to=someemail@gmail.com&amp;debugMode=true&amp;mail.smtp.starttls.enable=true"/>
</route>

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

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

如果您正在使用spring运行本地,我建议使用:

@Bean
public AmazonDynamoDB amazonDynamoDB() throws IOException {
    return AmazonDynamoDBClientBuilder.standard()
            .withCredentials(
                    new AWSStaticCredentialsProvider(
                            new BasicAWSCredentials("fake", "credencial")
                    )
            )
            .withClientConfiguration(new ClientConfigurationFactory().getConfig().withProtocol(Protocol.HTTP))
            .withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration("localhost:8443", "central"))
            .build();
}

它适用于我使用单元测试。

希望对大家有帮助!

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

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

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

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