2009-10-30 66 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