Mega Code Archive

 
Categories / C# Book / 08 Net
 

0591 HTTP-Specific Support

Headers Both WebClient and WebRequest allow you to add custom HTTP headers, as well as enumerate the headers in a response. A header is simply a key/value pair containing metadata, such as the message content type or server software. using System; using System.Net; using System.Threading; class ThreadTest { static void Main() { WebClient wc = new WebClient(); wc.Proxy = null; wc.Headers.Add("CustomHeader", "custom/1.0"); wc.DownloadString("http://www.yourDomain.com"); foreach (string name in wc.ResponseHeaders.Keys) Console.WriteLine(name + "=" + wc.ResponseHeaders[name]); } }