Examine the headers
/*
C#: The Complete Reference
by Herbert Schildt
Publisher: Osborne/McGraw-Hill (March 8, 2002)
ISBN: 0072134852
*/
// Examine the headers.
using System;
using System.Net;
public class HeaderDemo {
public static void Main() {
// Create a WebRequest to a URI.
HttpWebRequest req = (HttpWebRequest)
WebRequest.Create("http://www.osborne.com");
// Send that request and return the response.
HttpWebResponse resp = (HttpWebResponse)
req.GetResponse();
// Obtain a list of the names.
string[] names = resp.Headers.AllKeys;
// Display the header name/value pairs.
Console.WriteLine("{0,-20}{1}\n", "Name", "Value");
foreach(string n in names)
Console.WriteLine("{0,-20}{1}", n, resp.Headers[n]);
// Close the Response.
resp.Close();
}
}
Related examples in the same category