Removes the specified header from the collection. : WebHeaderCollection « Network « C# / C Sharp






Removes the specified header from the collection.

 
using System;
using System.Net;
using System.Net.Sockets;
using System.Text;

class MainClass
{
    public static void Main()
    {
        HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create("http://www.msn.com");
        WebHeaderCollection myWebHeaderCollection = myHttpWebRequest.Headers;
        myWebHeaderCollection.Set("Cache-Control", "no-cache");
        HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
        myWebHeaderCollection.Remove("Cache-Control");
        myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
        Console.WriteLine("Print request headers after removing Cache-Control for the new request:");
        myHttpWebResponse.Close();
    }
}

   
  








Related examples in the same category

1.WebHeaderCollection.Add Inserts the specified header into the collection.
2.Gets an array of header values stored in a header.
3.Tests whether the specified HTTP header can be set for the request.
4.Sets the specified header to the specified value.