C#获取http header信息的代码

如下资料是关于C#获取http header信息的内容。

public Dictionary GetHTTPResponseHeaders(string Url)

{

    Dictionary HeaderList = new Dictionary();

    WebRequest WebRequestObject = HttpWebRequest.Create(Url);

    WebResponse ResponseObject = WebRequestObject.GetResponse();

    foreach (string HeaderKey in ResponseObject.Headers)

        HeaderList.Add(HeaderKey, ResponseObject.Headers[HeaderKey]);

    ResponseObject.Close();

    return HeaderList;

}

foreach (string HeaderKey in Headers.Keys)

    Console.WriteLine("{0}: {1}", HeaderKey, Headers[HeaderKey]);

你可能感兴趣的:(C#获取http header信息的代码)