views:

19

answers:

1

Hi,

I want to perform a get request on a remote URL and then extract the headers returned.

Thanks for any help!

+1  A: 

As MSDN Documentation

If you make any request, POST or GET like:

// Creates an HttpWebRequest for the specified URL. 
HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(url); 

You will be getting always a Response object like:

// Sends the HttpWebRequest and waits for response.
HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse(); 

And you can get all the headers with:

myHttpWebResponse.Headers

And iterate through them like:

for(int i=0; i < myHttpWebResponse.Headers.Count; ++i)  
    Console.WriteLine("\nHeader Name:{0}, Value:1}",myHttpWebResponse.Headers.Keys[i],myHttpWebResponse.Headers[i]); 
Garis Suero