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

推荐订阅源

S
Schneier on Security
P
Proofpoint News Feed
Apple Machine Learning Research
Apple Machine Learning Research
WordPress大学
WordPress大学
博客园 - Franky
V
V2EX
爱范儿
爱范儿
J
Java Code Geeks
小众软件
小众软件
Last Week in AI
Last Week in AI
The Cloudflare Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Hugging Face - Blog
Hugging Face - Blog
T
The Blog of Author Tim Ferriss
酷 壳 – CoolShell
酷 壳 – CoolShell
The Register - Security
The Register - Security
GbyAI
GbyAI
Vercel News
Vercel News
Y
Y Combinator Blog
腾讯CDC
F
Fortinet All Blogs
I
InfoQ
N
Netflix TechBlog - Medium
B
Blog RSS Feed
D
Docker
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
量子位
博客园 - 司徒正美
阮一峰的网络日志
阮一峰的网络日志
The GitHub Blog
The GitHub Blog
Microsoft Security Blog
Microsoft Security Blog
V
Visual Studio Blog
博客园 - 三生石上(FineUI控件)
宝玉的分享
宝玉的分享
Blog — PlanetScale
Blog — PlanetScale
H
Help Net Security
云风的 BLOG
云风的 BLOG
A
About on SuperTechFans
Scott Helme
Scott Helme
T
Tor Project blog
U
Unit 42
Google Online Security Blog
Google Online Security Blog
PCI Perspectives
PCI Perspectives
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
NISL@THU
NISL@THU
D
Darknet – Hacking Tools, Hacker News & Cyber Security
aimingoo的专栏
aimingoo的专栏
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Stack Overflow Blog
Stack Overflow Blog
Security Archives - TechRepublic
Security Archives - TechRepublic

博客园 - lei1217

(转)android 4.0 蓝牙服务开启流程分析 转:MTK分布式编译提高编译速度(IncredBuild) 使用.NET实现断点续传(转载) MTK 图层,详细讲解加案例(转载) 字符串颠倒 .net的RadioButtonList控件的脚本操作 socket编程原理 SQL2000 文件与文件组操作 [转载]SQL Server 2005对海量数据处理 HTTP参考 - 转载 HTTP协议详解 - 转载 ASPAJAXExtSetup 转载 Response.ContentType 的参数属性 标准文件读写操作 C语言文件操作 Web/Js 调色板 进制转换 计算机进制转换汇总 浮动广告
C#请求远程服务器的资源
lei1217 · 2008-12-25 · via 博客园 - lei1217

using System.IO;

1、获取远程服务器文件的大小
public static long GetRemoteHTTPFileSize(string sURL)
{
      long size = 0L;
      try
      {
           System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(sURL);
           request.Method = "HEAD";

           System.Net.HttpWebResponse response = (System.Net.HttpWebResponse)request.GetResponse();

            size = response.ContentLength;
             response.Close();
        }
        catch
        {
             size = 0L;
        }
        return size;
}

2、下载远程服务器的文件
public static void GetRemoteHTTPFileDown(string sURL)
{
      Stream content = null;
      try
      {
               System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(URL);
                request.Method = "GET";

                System.Net.HttpWebResponse response = (System.Net.HttpWebResponse)request.GetResponse();

                content = response.GetResponseStream();
                StreamReader sr = new StreamReader(content, System.Text.Encoding.Default);
                string str = sr.ReadToEnd();
                StreamWriter sw = new StreamWriter(Server.MapPath("~/1.txt"), false, System.Text.Encoding.Unicode);
                sw.Write(str);
                sw.Flush();
                sw.Close();
                sr.Close();
                response.Close();
        }
       catch
       { }
}