How to Extract Request Headers
- 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]);