Get HTTP header
Shows how to access the HTTP headers from a given web adress.
/// <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; }
Snippet Details
-
AuthorJonas John
-
LicensePublic domain
-
LanguageC#
-
Created10/30/2007
-
Updated10/30/2007
-
Tagshttp, network
// Retrieve headers: Dictionary<string, string> Headers = GetHTTPResponseHeaders("http://www.jonasjohn.de/"); // And output them: foreach (string HeaderKey in Headers.Keys) Console.WriteLine("{0}: {1}", HeaderKey, Headers[HeaderKey]);
Sorry folks, comments have been deactivated for now due to the large amount of spam.
Please try to post your questions or problems on a related programming board, a suitable mailing list, a programming chat-room,
or use a QA website like stackoverflow because I'm usually too busy to answer any mails related
to my code snippets. Therefore please just mail me if you found a serious bug... Thank you!
Older comments:
None.