惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
Secure Thoughts
Security Latest
Security Latest
Simon Willison's Weblog
Simon Willison's Weblog
O
OpenAI News
GbyAI
GbyAI
L
LINUX DO - 最新话题
A
Arctic Wolf
T
Tor Project blog
G
GRAHAM CLULEY
I
InfoQ
博客园_首页
IT之家
IT之家
The Register - Security
The Register - Security
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
P
Proofpoint News Feed
The GitHub Blog
The GitHub Blog
Blog — PlanetScale
Blog — PlanetScale
N
Netflix TechBlog - Medium
K
Kaspersky official blog
博客园 - 三生石上(FineUI控件)
S
SegmentFault 最新的问题
U
Unit 42
PCI Perspectives
PCI Perspectives
量子位
P
Palo Alto Networks Blog
S
Securelist
T
Troy Hunt's Blog
博客园 - 【当耐特】
Recorded Future
Recorded Future
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
S
Security Affairs
Engineering at Meta
Engineering at Meta
T
The Blog of Author Tim Ferriss
博客园 - 聂微东
罗磊的独立博客
N
News and Events Feed by Topic
人人都是产品经理
人人都是产品经理
B
Blog RSS Feed
NISL@THU
NISL@THU
C
Cisco Blogs
T
Threatpost
有赞技术团队
有赞技术团队
Forbes - Security
Forbes - Security
Hugging Face - Blog
Hugging Face - Blog
Last Week in AI
Last Week in AI
T
The Exploit Database - CXSecurity.com
Cloudbric
Cloudbric
Cyberwarzone
Cyberwarzone
Google DeepMind News
Google DeepMind News
C
Cyber Attacks, Cyber Crime and Cyber Security

博客园 - 强悍的抽屉

基于 Dapper 的一个 DbUtils WebAPI 操作返回 c#版 mqtt 3.1.1 client 实现 mqtt 协议之 PINGREQ, PINGRESP 一个 go 文件服务器 ssdb MongoDB 刷新几次就报错 C# Win32API - 强悍的抽屉 - 博客园 回车跳转控件焦点 让程序只启动一次 -- Mutex C# 排序 WINDEF.h 变量类型 SqlHelper 数据库操作类2 SqlHelper 数据库操作类 第一个 Windows 应用程序 JavaScript 字符串处理函数 - 强悍的抽屉 - 博客园 JavaScript 字符串函数扩充 - 强悍的抽屉 - 博客园 C# 字符串处理一些方法 希望找人一起写个 Ajax 的封装 几种流行的JS框架的选择
httpWebRequest 文件下载
强悍的抽屉 · 2015-07-30 · via 博客园 - 强悍的抽屉

服务版本:

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();
      }
}