C#通过url获取http header的详细信息,存储在数据字典里面
/// <summary> /// Returns the responded HTTP headers of the given URL. /// </summary> /// <param name="Url">The adress.</param> /// <returns>List of headers</returns> public Dictionary<string, string> GetHTTPResponseHeaders(string Url) { Dictionary<string, string> HeaderList = new Dictionary<string, string>(); 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; } //用法: // Retrieve headers: Dictionary<string, string> Headers = GetHTTPResponseHeaders("http://www.75271.com"); // And output them: foreach (string HeaderKey in Headers.Keys) Console.WriteLine("{0}: {1}", HeaderKey, Headers[HeaderKey]);