Java 随机 SSLException 不支持的记录版本 Unknown-0.0
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23324807/
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
Randomly SSLException Unsupported record version Unknown-0.0
提问by daniele.guiducci
Sometimes the code below fails and sometimes it work. I'm using Java8. Is it a server side problem?
有时下面的代码失败,有时它工作。我正在使用 Java8。是服务器端的问题吗?
Exception in thread "main" javax.net.ssl.SSLException: Unsupported record version Unknown-0.0.
线程“main”中的异常 javax.net.ssl.SSLException: 不支持的记录版本 Unknown-0.0。
EDIT: I downgrade to JDK7 from JDK8 and it works. The only solution i found that works.
编辑:我从 JDK8 降级到 JDK7 并且它可以工作。我发现唯一有效的解决方案。
public static void main(String[] args) throws Exception {
URL u = new URL("https://c********.web.cddbp.net/webapi/xml/1.0/");
HttpURLConnection connection = (HttpURLConnection) u.openConnection();
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setInstanceFollowRedirects(false);
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "text/plain");
connection.setRequestProperty("charset", "utf-8");
connection.setRequestProperty("Content-Length", "" + 140);
connection.setUseCaches(false);
DataOutputStream wr = new DataOutputStream(connection.getOutputStream());
}
回答by Michael O'Connor
I got the same error message in a new java installation when trying to use an SSL connection that enforces 256-bit encryption. To fix the problem I found I needed to install the Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files (e.g. http://www.oracle.com/technetwork/java/javase/downloads/jce-7-download-432124.html)
尝试使用强制执行 256 位加密的 SSL 连接时,我在新的 java 安装中收到相同的错误消息。为了解决这个问题,我发现我需要安装 Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files(例如http://www.oracle.com/technetwork/java/javase/downloads/jce-7-download-432124。 html)
回答by Peter Escamilla
I had this line
我有这条线
SSLContext sc = SSLContext.getInstance("SSL");
Had to change it to
不得不把它改成
SSLContext sc = SSLContext.getInstance("TLSv1");
And now it works on both, java 7 and java 8
现在它适用于 java 7 和 java 8
Note: (In java 7 SSL and TLS both worked with the same url, in java 8 just tried TLSv1 but I guess SSLv1 also works)
注意:(在 java 7 SSL 和 TLS 都使用相同的 url,在 java 8 中只是尝试了 TLSv1,但我猜 SSLv1 也有效)
回答by Valen
According to the stack trace, the RecordVersion Unknow-0.0 is produced from here=> referenced from here=> which is invoked in InputRecord.readV3Record
根据堆栈跟踪,RecordVersion Unknow-0.0 是从这里生成的=>从这里引用=>在 InputRecord.readV3Record 中调用
most of the time, these two values should not be 0, the reason for this happening is probably the wrong response from server while handshaking.
大多数情况下,这两个值不应该是 0,发生这种情况的原因可能是握手时服务器的错误响应。
(This is not an answer though, just some information for easier figuring out the problem and solution)
(虽然这不是答案,只是一些信息,可以更轻松地找出问题和解决方案)