当前位置: 首页 > news >正文

Http Download

Http / Https 下载文件,startWith不能验证https,测试地址:https://storage.googleapis.com/golang/go1.7.3.windows-amd64.msi

private static final Logger logger = Logger.getLogger(MethodHandles.lookup().lookupClass());private static void sunNetSsl() {System.setProperty("java.protocol.handler.pkgs","com.sun.net.ssl.internal.www.protocol");Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());}private static void javaxNetSsl(){TrustManager[] trustAllCertArr = new TrustManager[]{new X509TrustManager() {public X509Certificate[] getAcceptedIssuers() {return null;}public void checkServerTrusted(X509Certificate[] certArr,String authType) throws CertificateException {}public void checkClientTrusted(X509Certificate[] certArr,String authType) throws CertificateException {}}};//activate trust managertry {SSLContext sc = SSLContext.getInstance("SSL");sc.init(null,trustAllCertArr,new SecureRandom());HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());} catch (NoSuchAlgorithmException | KeyManagementException e) {e.printStackTrace();}}public static void download(String downloadUrl,String fileName,boolean isHttps) throws IOException{if (isHttps) {logger.info(isHttps);javaxNetSsl();//sunNetSsl();}URL url = new URL(downloadUrl);try(ReadableByteChannel rbc = Channels.newChannel(url.openStream());FileOutputStream fos = new FileOutputStream(fileName)){fos.getChannel().transferFrom(rbc,0,Long.MAX_VALUE);}catch(IOException e){e.printStackTrace();}}

http://www.lryc.cn/news/334924.html

相关文章:

  • 【Android】Glide加载SVG,SVG转PNG
  • Spring、SpringMVC、Springboot三者的区别和联系
  • 一点点安全资料:网络安全扩展
  • vscode的源码插件GitHub Repositories
  • 如何定义快速开发平台框架?有何突出优势?
  • 二分练习题——奶牛晒衣服
  • python工具包【1】 -- 不同操作系统路径转换
  • JAVA中@FunctionalInterface 注解使用
  • 【Spring Cloud Alibaba】9 - OpenFeign集成Sentinel实现服务降级
  • Chrome浏览器如何跟踪新开标签的网络请求?
  • html写一个登录注册页面
  • Stable Diffusion|Ai赋能电商 Inpaint Anything
  • 启明智显M系列--工业级HMI芯片选型表
  • C语言面试题之最小高度树
  • 【随笔】Git 高级篇 -- 整理提交记录(上)cherry-pick(十五)
  • 上门服务小程序|上门服务系统|上门服务软件开发流程
  • Vuex(vue 项目中实现 频繁、大范围数据共享的技术方案)
  • 【Spring Cloud】服务容错中间件Sentinel入门
  • 算法刷题记录 Day36
  • 面试必问 - CSS 中元素居中小技巧
  • Chatgpt润色论文
  • 51单片机实验02- P0口流水灯实验
  • 使用git 和 github协作开发
  • DataX,MongoDB数据导入hdfs与mysql
  • 【OpenCV-颜色空间】
  • 电脑硬盘分区表的两种格式:MBR 和 GPT
  • kafka 常用非基础的核心设置项
  • 杂谈 EV之我见
  • 白色磨砂质感html5页源码
  • sqlite建立数据库