How to Extract Request Headers

104 18
    • 1). Create the variables for the webpage and response from the webpage. The following code creates your main variables:

      HttpWebRequest request =(HttpWebRequest)WebRequest.Create("http://www.mydomain.com");

      HttpWebResponse response =(HttpWebResponse)request.GetResponse();

    • 2). Get the headers. Use the following code to get the collection of headers from the webpage response:

      WebHeaderCollection header = request.Headers;

    • 3). Write each header to the screen. This code helps you to test the code and verify the headers sent from the webpage. You can also use the headers to manipulate the response. Add the following code to view the headers:

      for (int i = 0; i < header.Count; i++)

      Response.Write(" {0} : {1}",header.GetKey(i), header[i]);

Subscribe to our newsletter
Sign up here to get the latest news, updates and special offers delivered directly to your inbox.
You can unsubscribe at any time

Leave A Reply

Your email address will not be published.