开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜