2012-09-14 26 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> 
相关问题