2009-10-30 69 views
0

我如何连接一个网站,然后如何在asp.net中控制其头/ http状态码?服务器头检查器

我试过的HttpWebRequest/WebRequest的/ Stream类,但我失败了......

回答

1

您可以使用WebRequest类此:

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

线wr.Method = WebRequestMethods.Http.Head;使得WebRequest对象仅检索标题(如果这是您唯一感兴趣的东西,则无法下载整个页面)。如果您要想要整页,请改为使用wr.Method = WebRequestMethods.Http.Get;

+0

感谢Fredrik,我只对标题感兴趣......它是真正有用的:) – ogun 2009-10-30 10:55:03