服务版本:

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 = ;
do
{
var buffer = new byte[];
count = stream.Read(buffer, , buffer.Length);
fs.Write(buffer, , count);
} while (count > );
}
}
}
Console.ReadKey();
}
}

httpWebRequest 文件下载的更多相关文章

  1. C# 获取文件下载的各种方法

    public class RemoteDownload { public static void DownLoad(string addressUrl,string localName) { //下载 ...

  2. ASP.NET Web API 2 之文件下载

    Ø  前言 目前 ASP.NET Web API 的应用非常广泛,主要承载着服务端与客户端的数据传输与处理,如果需要使用 Web API 实现文件下载,该 实现呢,其实也是比较简单,以下示例用于下载安 ...

  3. HttpWebRequest、HttpWebResponse、HttpClient、WebClient等http网络访问类的使用示例汇总

    工作中长期需要用到通过HTTP调用API以及文件上传下载,积累了不少经验,现在将各种不同方式进行一个汇总. 首先是HttpWebRequest: /// <summary> /// 向服务 ...

  4. C# 文件下载断点续传

    C# 文件下载断点续传的一个类 using System; using System.Collections.Generic; using System.Linq; using System.Text ...

  5. HttpWebRequest中的ContentType详解

    1.参考网络资源: http://blog.csdn.net/blueheart20/article/details/45174399  ContentType详解 http://www.tuicoo ...

  6. WebClient HttpWebRequest 下载文件到本地

      处理方式: 第一种:  我们需要获取文件,但是我们不需要保存源文件的名称 public void DownFile(string uRLAddress, string localPath, str ...

  7. Android 浏览器 —— 使用 WebView 实现文件下载

    对当前的WebView设置下载监听 mCurrentWebView.setDownloadListener(new DownloadListener() { @Override public void ...

  8. C# 文件下载 : WinINet

    在 C# 中,除了 WebClient 我们还可以使用一组 WindowsAPI 来完成下载任务.这就是 Windows Internet,简称 WinINet.本文通过一个 demo 来介绍 Win ...

  9. ASP.net MVC 文件下载的几种方法(欢迎讨论)

    在ASP.net MVC 中有几种下载文件的方法 前提:要下载的文件必须是在服务器目录中的,至于不在web项目server目录中的文件下载我不知道,但是还挺想了解的. 第一种:最简单的超链接方法,&l ...

随机推荐

  1. ubuntu下virtualbox安装freebsd及初步配置

    最近尝试了在虚拟机中安装freebsd并进行尝试性的使用 获取镜像 在freebsd的官网,https://www.freebsd.org,即可看到 "Download Freebsd&qu ...

  2. bind类成员函数

    首先描述一个情景: 先贴出代码: class Solution { public: bool compare(int a, int b) { return a > b; } int functi ...

  3. python基础===pendulum '''Python datetimes made easy.'''

    https://pypi.python.org/pypi/pendulum Pendulum的一大优势是内嵌式取代Python的datetime类,可以轻易地将它整合进已有代码,并且只在需要的时候才进 ...

  4. python的时间和日期--time、datetime应用

    time >>> import time >>> time.localtime() #以time.struct_time类型,打印本地时间 time.struct_ ...

  5. dos命令连接mysql并且查看编码方式

    打开cmd: 输入:mysql -hlocalhost -uroot -p 然后: show variables like 'char%';

  6. display:inline、block、inline-block三者之间的区别

    1. display:block就是将元素显示为块级元素. block元素的特点: 总是在新行上开始: 高度,行高以及顶和底边距都可控制: 宽度缺省是它的容器的100%,除非设定一个宽度:(<d ...

  7. asp.net的Server.MapPath方法

    Server.MapPath()的功能: 返回与 Web 服务器上的指定虚拟路径相对应的物理文件路径. 命名空间: System.Web 程序集: System.Web(在 System.Web.dl ...

  8. 单源点最短路径的Dijkstra算法

    在带权图(网)里,点A到点B所有路径中边的权值之和为最短的那一条路径,称为A,B两点之间的最短路径;并称路径上的第一个顶点为源点(Source),最后一个顶点为终点(Destination).在无权图 ...

  9. The 18th Zhejiang University Programming Contest Sponsored by TuSimple -C Mergeable Stack

    题目链接 题意: 题意简单,就是一个简单的数据结构,对栈的模拟操作,可用链表实现,也可以用C++的模板类来实现,但是要注意不能用cin cout,卡时间!!! 代码: #include <std ...

  10. zoj 4020 The 18th Zhejiang University Programming Contest Sponsored by TuSimple - G Traffic Light(广搜)

    题目链接:The 18th Zhejiang University Programming Contest Sponsored by TuSimple - G Traffic Light 题解: 题意 ...