Tests whether the specified HTTP header can be set for the request. : WebHeaderCollection « Network « C# / C Sharp






Tests whether the specified HTTP header can be set for the request.

 
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");
       HttpWebResponse myHttpWebResponse = (HttpWebResponse) myHttpWebRequest.GetResponse();
      WebHeaderCollection myWebHeaderCollection = myHttpWebResponse.Headers;
      for (int i = 0; i < myWebHeaderCollection.Count;i++)  
      {
      if(WebHeaderCollection.IsRestricted(myWebHeaderCollection.AllKeys[i]))
        Console.WriteLine("'{0}' is a restricted header", myWebHeaderCollection.AllKeys[i]);
      else
        Console.WriteLine("'{0}' is not a restricted header", myWebHeaderCollection.AllKeys[i]);
      }
      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.Removes the specified header from the collection.
4.Sets the specified header to the specified value.