我收到javax.net.ssl.SSLHandshakeException:当我尝试通过互联网进行Web服务的HTTPS发布时,握手异常期间远程主机关闭连接.但是相同的代码适用于其他Internet托管的Web服务.我尝试过很多东西,没有什么可以帮助我.我在这里发布了示例代码.有谁可以帮我解决这个问题?
public static void main(String[] args) throws Exception {
String xmlServerURL = "https://example.com/soap/WsRouter";
URL urlXMLServer = new URL(xmlServerURL);
// URLConnection supports HTTPS protocol only with JDK 1.4+
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(
"xxxx.example.com", 8083));
HttpURLConnection httpsURLConnection = (HttpURLConnection) urlXMLServer
.openConnection(proxy);
httpsURLConnection.setRequestProperty("Content-Type","text/xml; charset=utf-8");
//httpsURLConnection.setDoInput(true);
httpsURLConnection.setDoOutput(true);
httpsURLConnection.setConnectTimeout(300000);
//httpsURLConnection.setIgnoreProxy(false);
httpsURLConnection.setRequestMethod("POST");
//httpsURLConnection.setHostnameVerifier(DO_NOT_VERIFY);
// send request
PrintWriter out = new PrintWriter(
httpsURLConnection.getOutputStream());
StringBuffer requestXML = new StringBuffer();
requestXML.append(getProcessWorkOrderSOAPXML());
// get list of user
out.println(requestXML.toString());
out.close();
out.flush();
System.out.println("XML …Run Code Online (Sandbox Code Playgroud) 在Tomcat上运行JDK7应用程序,它具有以下env设置:
-Dhttps.protocols=TLSv1.1,TLSv1.2
Run Code Online (Sandbox Code Playgroud)
上述设置可确保在进行API调用等过程中通过HTTPS连接时不使用TLS 1.0.
我们还使用org.springframework.mail.javamail.JavaMailSenderImpl类发送外发SMTP电子邮件,并使用这些道具:
mail.smtp.auth=false;mail.smtp.socketFactory.port=2525;mail.smtp.socketFactory.fallback=true;mail.smtp.starttls.enable=true
Run Code Online (Sandbox Code Playgroud)
问题是,当SMTP电子邮件服务器升级到TLS1.2时,它的连接失败.
javax.net.ssl.SSLHandshakeException:握手期间远程主机关闭连接
是否存在强制TLS1.2协议的设置或代码更改?
我做了一些搜索,看起来这些env设置仅适用于applet和Web客户端,而不适用于服务器端应用程序
-Ddeployment.security.SSLv2Hello=false -Ddeployment.security.SSLv3=false -Ddeployment.security.TLSv1=false
Run Code Online (Sandbox Code Playgroud)