httpWebRequest 文件下载
2015-07-30 14:25
686 查看
服务版本:
go file system ssdb
github: https://github.com/dtxlink/gfs
go file system ssdb
github: https://github.com/dtxlink/gfs
上一篇: 一个 go 文件服务器 ssdb
通过httpWebRequest 下载文件的简短代码
class Program { static void Main(string[] args) { const string uri = "http://127.0.0.1/adde61103208ff33deb6e8fa70f79706"; var req = WebRequest.Create(uri) as HttpWebRequest; //req.ContentType = "application/octet-stream"; if (req != null) { var response = req.GetResponse() as HttpWebResponse; if (response != null) { Console.WriteLine("ContentType:" + response.ContentType); var stream = response.GetResponseStream(); if (stream != null) { string format = string.Empty; switch (response.ContentType) { case "image/jpeg": format = "jpg"; break; case "audio/amr": format = "amr"; break; } var path = string.Format(@"c:\\1.{0}", format); //var fs = new FileStream($"c:\\1.{format}", FileMode.Create); var fs = File.Create(path); int count = 0; do { var buffer = new byte[4096]; count = stream.Read(buffer, 0, buffer.Length); fs.Write(buffer, 0, count); } while (count > 0); } } } Console.ReadKey(); } }
相关文章推荐
- 利用HttpWebRequest访问WebApi
- 网络中数据传输过程的分析
- 【转载】深入浅出http请求
- cmd (网络命令大全)
- 好霸气!Windows 10发布首日全球网络流量飙升35%
- Socket 通信原理(Android客户端和服务器以TCP UDP方式互通)
- $http
- Web Server 和 HTTP协议
- HTTP 和 HTTPS 协议
- 毕向东day23--java基础-网络总结
- HTTP状态码
- 【HttpClient4.5中文教程】【第一章 :基础】1.1执行请求(二)
- HttpClient 发送 HTTP、HTTPS 请求的简单封装
- SpringMVC 流程(4)-- HttpMessageConverter
- 使用genymotion和chares网络调试设置代理方法
- [Tool] Chrome内的本地网页,使用XMLHttpRequest读取本地档案
- 网络请求开源库volley和AsyncHttp的使用
- Xutils框架-HTTP源码详解
- HTTP协议中的GET和POST方法
- 关于映射网络驱动 网络存在问题不能连接的原因