编者按:通过此以下程序的调用,让我们明白在程序读取一个页面的时候,都从头(Head)里面读取到了什么!
using System;

using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DownloadFile_help2
{
    class Program
    {
        static void Main(string[] args)
        {
            System.Net.HttpWebRequest hwr = (System.Net.HttpWebRequest)System.Net.WebRequest.Create("http://210.45.192.243/jyzd");

             hwr.Method = "GET";
            // (msdn标注) Method 属性只能设置为 GET 和 POST 方法。任何其他 HTTP 1.1 或 1.0 协议谓词(例如,HEAD、PUT、DELETE、TRACE 或 OPTIONS)都将引发 NotSupportedException 异常。

            System.Net.WebResponse response = hwr.GetResponse();

            string[] str = response.Headers.AllKeys;
            foreach (string temp in str)
            {
                Console.Write("{0} {1} ", temp, temp.Length);
                Console.WriteLine("{0}", response.Headers[temp]);
            }
        }
    }
}

//输出结果
//Content-Length 14 252607 字节流的长度,即当前页面的大小
//Cache-Control 13 private   指示客户端应该如何缓存改内容
//Content-Type 12 text/html; charset=gb2312           ContentType 属性包含请求的媒体类型
//Date 4 Wed, 07 Oct 2009 06:31:24 GMT 获取此页面时的服务器时间
//Server 6 Microsoft-IIS/6.0  服务器类型
//X-AspNet-Version 16 2.0.50727 版本
//X-Powered-By 12 ASP.NET  包含此软件的额外信息

posted on 2009-10-07 14:50  qqhfeng16  阅读(2394)  评论(3编辑  收藏  举报