使用语义 HTML 的评论列表?
java - 在 Java 中下载图像时忽略证书
问题描述
我正在使用下面的代码下载只能通过 HTTPS 获得的图像。证书已过期,所以如果我想下载图片,我必须手动点击浏览器中的忽略证书错误。我怎样才能在我的代码中做同样的事情?
URL website = new URL("https://domain/image.jpg");
ReadableByteChannel rbc = Channels.newChannel(website.openStream());
FileOutputStream fos = new FileOutputStream("C:\\temp\\image.jpg");
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
fos.close();
这是我使用此代码得到的异常:
Exception in thread "main" javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake
at sun.security.ssl.SSLSocketImpl.readRecord(Unknown Source)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source)
at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)
at sun.security.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.http.HttpURLConnection.getInputStream0(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(Unknown Source)
at java.net.URL.openStream(Unknown Source)
at DownloadImage.main(DownloadImage.java:17)
Caused by: java.io.EOFException: SSL peer shut down incorrectly
at sun.security.ssl.InputRecord.read(Unknown Source)
解决方案
推荐阅读
- angularjs - Can't retrieve data from controller AngularJS
- swift - Firebase says that my rules are insecure, why?
- kentico - 如何防止由 API 调用引起的全局事件处理程序触发
- git - 如何用新的本地项目覆盖远程 git 存储库
- java - 如何防止其他具有管理员权限的应用程序禁用通过 JNativeHook 注册的钩子?
- git - 变基后如何将分支与原点/分支同步?
- html - 我应该使用
- ,
- ,
或者 - javascript - 仅在打开时使用 ajax 填充 select2
- emacs - 避免在comint模式下意外执行
- sql - SQL/Hive 如何将两个不同的查询组合成一个具有不同列的结果