Mega Code Archive

 
Categories / C# / Network
 

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