从一个https的url获取zip压缩包,压缩包里面是多个excel文件,excel文件包含两个不同的sheet,字段不一样,要解析成java对象。
excel文件是要密码的,代码中的url获取的压缩包中的exce密码是91440300555442072M。
目前能从url中获取流,但是转为zipInputStream后,总是为空。
URL url = new URL("https://pubapi.holytax.com/pre/xz/sstfpgj?uid=764a332f16d1291ad2fd1d6c08d177ff");
SSLContext sslContext = SSLContext.getInstance("SSL", "SunJSSE");
// 创建SSLContext对象,并使用我们指定的信任管理器初始化
TrustManager[] tm = {new MyX509TrustManager()};
sslContext.init(null, tm, new java.security.SecureRandom());
HostnameVerifier ignoreHostnameVerifier = (s, sslsession) -> {
log.warn("Hostname is not matched for cert.");
return true;
};
HttpsURLConnection.setDefaultHostnameVerifier(ignoreHostnameVerifier);
HttpsURLConnection.setDefaultSSLSocketFactory(sslContext.getSocketFactory());
HttpsURLConnection httpsURLConnection = (HttpsURLConnection) url.openConnection();
httpsURLConnection.setConnectTimeout(6000);
httpsURLConnection.setReadTimeout(6000);
int code = httpsURLConnection.getResponseCode();
if (code != HttpURLConnection.HTTP_OK) {
throw new Exception("文件读取失败");
}
ZipInputStream zipInputStream = new ZipInputStream(new BufferedInputStream(httpsURLConnection.getInputStream()), Charset.forName("GBK"));
// 这里每次读取都是空???
while (zipInputStream.getNextEntry() != null) {
}