java - 如何从 url 下载 https 文件
问题描述
我正在尝试从这些网址下载
“ https://www.treasury.gov/ofac/downloads/sdn.xml ” 但它是说
"javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target"
我尝试了以下两个,但它不起作用 1. System.setProperty("com.sun.security.enableAIAcaIssuers","true");
2. 将我的 java 版本从 1.7 更新到 1.8.0_121
download("https://www.treasury.gov/ofac/downloads/sdn.xml","D:\\AML_Files\\Download_Check\\sdnList.xml");
public static void download(String url, String fileName) throws Exception {
//System.setProperty("com.sun.security.enableAIAcaIssuers","true");
try (InputStream in = URI.create(url).toURL().openStream()) {
Files.copy(in, Paths.get(fileName));
}
}
我想在我的系统中下载 xml 文件,然后将该 xml 文件数据插入数据库表
解决方案
您需要在 JRE 中添加有效证书。
推荐阅读
- firebase - 检查 querysnapshot 是否已与 firestore 建立连接
- charts - 在 Visual Studio 中控制图表控件上的垂直网格线
- php - 在 mac 上使用 Atom 在此处运行 PHP-server
- java - 我可以使用 jpackage (Java 17) 制作我的应用程序的可安装 32 位版本吗?
- mongodb - 如何对mongodb文档中数组内所有对象中存在的特定数字字段求和
- python-3.x - pip 脚本未运行
- python - 在 pytorch 中使用神经网络作为另一个神经网络的损失
- machine-learning - Python 中的超参数优化与单独的验证集
- laravel - Laravel Eloquent 选择小数点前的第一个字符
- r - 计算 GPS 数据 R 中事件的发生次数