使用 FileUtils.copyURLToFile 设置 SSL 版本 [英] Setting SSL version with FileUtils.copyURLToFile
问题描述
我正在使用 FileUtils.copyURLToFile 将 url 复制到本地文件中.该 URL 使用 https.在他们更改 SSL 版本之前,它运行得非常好.
I am using FileUtils.copyURLToFile to copy a url into a local file. The URL is using https. It worked perfectly fine until they changed the SSL version.
有没有办法用 apache commons.io 指定 SSL 版本?例如类似于 这个问题 但允许我继续使用 FileUtils.copyURLToFile.
Is there a way to specify the SSL version with the apache commons.io? eg something like in this question but allowing me to keep using FileUtils.copyURLToFile.
推荐答案
作为一种解决方法,您可以使用 HttpsURLConnection 打开连接,设置 SSL 版本,然后使用 FileUtils.copyURLToFile:
As a workaround you can use HttpsURLConnection to open connection, set SSL version and then use FileUtils.copyURLToFile:
SSLContext context = SSLContext.getInstance("TLSv1.2");
context.init(null, null, null);
HttpsURLConnection.setDefaultSSLSocketFactory(context.getSocketFactory());
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
FileUtils.copyURLToFile(connection.getURL(), file);
这篇关于使用 FileUtils.copyURLToFile 设置 SSL 版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!