开发者

Server Header Checker

开发者 https://www.devze.com 2022-12-09 17:03 出处:网络
how do i connect a web site and then how can i control its header/http status code in asp.net? i tried HttpWebRequest/WebRequest/Stream class 开发者_StackOverflow中文版but i failed...You can use the

how do i connect a web site and then how can i control its header/http status code in asp.net?

i tried HttpWebRequest/WebRequest/Stream class 开发者_StackOverflow中文版but i failed...


You can use the WebRequest class for this:

WebRequest wr = WebRequest.Create("http://www.example.com");
wr.Method = WebRequestMethods.Http.Head;
using (HttpWebResponse response = (HttpWebResponse)wr.GetResponse())
{
    Console.WriteLine(response.StatusCode);
}

The line wr.Method = WebRequestMethods.Http.Head; makes the WebRequest object to retrieve the headers only (if this is the only thing you are interested in, there is no use downloading the full page). If you want the full page, use wr.Method = WebRequestMethods.Http.Get; instead.

0

精彩评论

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

关注公众号