httpclient htmlunit下载单个文件
2024-10-01 21:50:22
httpclient
public class Download {
public static void main(String[] args) throws ClientProtocolException, IOException {
String url = "http://1251214202.vod2.myqcloud.com/8f3139d3vodgzp1251214202/c9bff9c47447398155998582539/5nFpW8vzdYAA.mp3";
CloseableHttpClient client = HttpClients.createDefault();
HttpGet get = new HttpGet(url);
CloseableHttpResponse response = client.execute(get);
if(response.getStatusLine().getStatusCode() == 200) {
HttpEntity entity = response.getEntity();
// System.out.println(entity.getContentLength());
IOUtils.write(IOUtils.readFully(entity.getContent(),(int)entity.getContentLength()),new FileOutputStream("f:/枯叶双子.mp3"));
}
response.close();
get.abort();
client.close();
}
}
htmlunit
public class Download {
public static void main(String[] args) throws FailingHttpStatusCodeException, MalformedURLException, IOException {
WebClient client = new WebClient(BrowserVersion.CHROME);
String url = "http://1251214202.vod2.myqcloud.com/8f3139d3vodgzp1251214202/c9bff9c47447398155998582539/5nFpW8vzdYAA.mp3";
Page page = client.getPage(url);
InputStream contentAsStream = page.getWebResponse().getContentAsStream();
IOUtils.write(IOUtils.readFully(contentAsStream,(int)page.getWebResponse().getContentLength()),new FileOutputStream("f:/枯叶双子111.mp3"));
client.close();
}
}
最新文章
- 关于seajs模块化的搭建
- mysql connector 和 sqlserver ado.net 的区别
- web一周
- 转来的。。。 关于return 的一些事情
- 领域模型中的实体类分为四种类型:VO、DTO、DO、PO
- QT 按钮(4种样式)
- 使用ambari搭建Hadoop平台
- Spark源码的编译过程详细解读(各版本)
- Csharp 简单操作Word模板文件
- 解决Sqlite UTF-8中文数据格式在DOS窗口下中文乱码
- node.js中favicon.ico请求两次问题
- 《C++ 标准库》读书笔记 - 第二章 Introduction to C++ and the Standard Library
- MySql基础笔记(二)Mysql语句优化---索引
- c语言模拟c++的继承和多态
- Team Foundation Server 2013 KEY(密钥)
- Iframe高度自适应(兼容IE/Firefox、同域/跨域)
- java 泛型详解-绝对是对泛型方法讲解
- 20155339《java程序设计》第十二周课堂实践总结
- 《Java核心技术》 -- 读书笔记 ② - 类 | 对象 | 接口
- PHP系统学习1
热门文章
- JQuery EasyUI Combobox 实现省市二级联动菜单
- Maven学习总结(16)——深入理解maven生命周期和插件
- 老李的菜园 mysql 自定义函数
- 去哪网实习总结:用到的easyui组件总结(JavaWeb)
- 2.CCGridAction(3D效果),3D反转特效,凸透镜特效,液体特效,3D翻页特效,水波纹特效,3D晃动的特效,扭曲旋转特效,波动特效,3D波动特效
- ZOJ List the Books 水~
- php实现判断树的子结构
- Ditto —— windows 剪贴板增强小工具(复制粘贴多条记录)
- python 升级pip
- ASP.Net WebAPI HttpDelete/PUT方法运行或发布到生产服务器上后出现405(Method Not Allowed)错误的解决办法