我需要检查某些URL使用哪个TLS版本。 我用过
try {
myUrl = new URL(url);
HttpsURLConnection conn = (HttpsURLConnection) myUrl.openConnection();
logger.debug("connection made...");
SSLSocketFactory sslsocketfactory = (SSLSocketFactory) SSLSocketFactory.getDefault();
conn.setSSLSocketFactory(sslsocketfactory);
SSLSocket socket = (SSLSocket) sslsocketfactory.createSocket(myUrl.getHost(), 443);
String[] protocols = socket.getEnabledProtocols();
String enabledProtocols="";
for (String protocol : protocols )
enabledProtocols=enabledProtocols+protocol+" ";
logger.info("enabled protocols: "+enabledProtocols);
SSLSession session = socket.getSession();
logger.info("used protocol: "+session.getProtocol());
result=result+session.getProtocol()+";"+enabledProtocols+";";
conn.disconnect();
} catch (Exception e) {
result=result+"error while connecting to bank";
logger.debug(url, e);
}
但是sslsocketfactory.createSocket似乎被代理服务器阻止,因此我不能使用SSLSocket类 我得到java.net.ConnectException或UnknownHostException。没有代理,代码可以正常工作