I want to perform a get request on a remote URL and then extract the headers returned开发者_StackOverflow社区.
Thanks for any help!
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]);
精彩评论