Gets an array of header values stored in a header. : WebHeaderCollection « Network « C# / C Sharp






Gets an array of header values stored in a header.

 
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++) {
            String header = myWebHeaderCollection.GetKey(i);
            String[] values = myWebHeaderCollection.GetValues(header);
            if(values.Length > 0) {
                Console.WriteLine("The values of {0} header are : ", header);
                for(int j = 0; j < values.Length; j++) 
                    Console.WriteLine("\t{0}", values[j]);
            }
        }
        myHttpWebResponse.Close();
   }
}

   
  








Related examples in the same category

1.WebHeaderCollection.Add Inserts the specified header into the collection.
2.Tests whether the specified HTTP header can be set for the request.
3.Removes the specified header from the collection.
4.Sets the specified header to the specified value.