使用hutool通過httpUtil下載檔案
阿新 • • 發佈:2021-10-18
構造Url
//url示例http://192.168.2.13:18080/api/proxy/download/cutRecord?app=51342330001328100004&stream=51342330001328100004&startTime=2021-10-18%2010%3A10%3A01&seconds=10 String buildUrl = UrlBuilder.create() .setScheme("http") //http方式 .setHost("192.168.2.13") //ip .setPort("18080") //埠 .addPath("/api").addPath("proxy").addPath("download").addPath("cutRecord") .addQuery("app","51342330001328100004") .addQuery("stream","51342330001328100004") .addQuery("startTime","2021-10-18 10:10:01") .addQuery("seconds","10") .setCharset(Charset.forName(CharsetUtil.UTF_8)) //這裡需要對傳的2021-10-18 10:10:01 UrlEncode編碼 .build();
//通過HttpUtil.downloadFile 下載檔案
long file = HttpUtil.downloadFile(buildUrl, "d:/test02.mp4"); //下載並建立d:/test02.mp4