.NET下载网页图片
2016-07-26 18:08
281 查看
两种方式:WebRequest 和 WebClient: public void DownloadImage(string url, string path) { WebRequest request = WebRequest.Create(url); request.ContentType = "impage/jpg"; WebResponse response = request.GetResponse(); using (Stream reader = response.GetResponseStream()) { using (FileStream writer = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write)) { byte[] buffer = new byte[512]; int c = 0; while ((c = reader.Read(buffer, 0, buffer.Length)) > 0) { writer.Write(buffer, 0, c); } } } } //public void DownloadImage(string url, string path) //{ // WebClient client = new WebClient(); // client.DownloadFile(url, path); //}
相关文章推荐
- hdu 5754 Life Winner Bo 博弈论
- 安装android
- 杭电-2141 三个数组找定值(二分)
- HBase的子节点的RegionServer无法启动
- 队列的链表实现(FIFO)
- 在C# WinForm 中嵌入另一个.EXE程序,详细步骤
- HDU(2199)Can you solve this equation?二分
- 从wap页面跳转app(Android)
- intellj idea 初体验
- 安装phpredis扩展
- tools:replace="android:icon" 的作用和替代方法
- IO流4(补充
- jQuery.nivo.slider.js 幻灯片图片切换
- smarty汇总
- jsp网站环境搭建
- Can you find it?(二分)
- RecyclerView添加Header的正确方式
- 设计模式之观察者模式
- 安卓学习笔记---RecyclerView的五大开源项目-解决办法
- OC数据持久化