2012-09-14 31 views
4

我只是想知道是否有一種方法來測試從服務器返回的404錯誤頁面是該服務器的默認錯誤頁面(我主要考慮從IIS返回的默認404頁面)和自定義一個已被創建爲特定網站?有沒有區分自定義錯誤頁面和網頁默認錯誤頁面的方法?

當我向服務器發出請求時,會返回404錯誤。有時,標題中的內容長度爲0(通常由瀏覽器處理),否則返回錯誤頁面。這意味着內容長度現在不再是0,因此我不能輕鬆區分什麼是自定義和簡單的舊默認頁面。

我已經考慮了一些內容分析方法,其中大部分內存很大(特別是對於較大的頁面),我想知道是否有人找到了比較這樣的兩個網頁的巧妙方法。

任何幫助/指針將不勝感激!

回答

0

只比較返回頁面的HTML。更可能的是,您將頁面接收爲簡單的字符串。只需將您收到的字符串與您存儲在代碼中的字符串進行比較,如下面列出的代碼。

的IIS7默認的404頁:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/> 
<title>404 - File or directory not found.</title> 
<style type="text/css"> 
<!-- 
body{margin:0;font-size:.7em;font-family:Verdana, Arial, Helvetica, sans-serif;background:#EEEEEE;} 
fieldset{padding:0 15px 10px 15px;} 
h1{font-size:2.4em;margin:0;color:#FFF;} 
h2{font-size:1.7em;margin:0;color:#CC0000;} 
h3{font-size:1.2em;margin:10px 0 0 0;color:#000000;} 
#header{width:96%;margin:0 0 0 0;padding:6px 2% 6px 2%;font-family:"trebuchet MS", Verdana, sans-serif;color:#FFF; 
background-color:#555555;} 
#content{margin:0 0 0 2%;position:relative;} 
.content-container{background:#FFF;width:96%;margin-top:8px;padding:10px;position:relative;} 
--> 
</style> 
</head> 
<body> 
<div id="header"><h1>Server Error</h1></div> 
<div id="content"> 
<div class="content-container"><fieldset> 
    <h2>404 - File or directory not found.</h2> 
    <h3>The resource you are looking for might have been removed, had its name changed, or is temporarily unavailable.</h3> 
</fieldset></div> 
</div> 
</body> 
</html> 
相關問題