首页 > 解决方案 > 如何从 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 文件数据插入数据库表

标签: java

解决方案


您需要在 JRE 中添加有效证书。


推荐阅读