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]);
    }

}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.