开发者

extract header info from a get request on a remote URL in asp.net?

开发者 https://www.devze.com 2023-01-15 07:45 出处:网络
I want to perform a get request on a remote URL and then extract the headers returned开发者_StackOverflow社区.

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]); 
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号