测试指定页面是否存在
作者:cmscn 日期:2007-09-01
<html>
<head>
<title>本程序用于测试指定页面是否存在</title>
<script language=javascript>
function translateHttpHeader(header) {
var meaning = "没有关于HTTP 标头:http-"+header + " 的中文信息"
switch(header) {
case 400: meaning = "请求无效" ;break;
case 401: meaning = "要求密码";break ;
case 401.1: meaning = "无权查看网页,未授权:登录失败" ;break;
case 403: meaning = "拒绝访问" ;break;
case 403.7: meaning = "要求客户证书" ;break;
case 404: meaning = "文件没找到" ;break;
case 405: meaning = "禁止访问资源";break;
case 406: meaning = "无法显示资源,无法接受";break;
case 407: meaning = "要求代理身份验证";break;
case 410: meaning = "网页不存在,永久不可用";break;
case 412: meaning = "先决条件失败" ;break;
case 414: meaning = "请求无效,URI 太长" ;break;
case 500: meaning = "内部服务器错误" ;break;
case 500.11: meaning = "网站关闭" ;break;
case 500.12: meaning = "应用程序重新启动" ;break;
case 500.13: meaning = "服务器太忙" ;break;
}
return meaning
}
function postRequest(postTo,Method) {
//尝试用XMLHTTP测试服务器。
try {
var xhttp= new ActiveXObject("Microsoft.XMLHTTP")
}
catch (e) {
longinfo.innerHTML="无法创建对象Microsoft.XMLHTTP"
}
try {
xhttp.open(Method,postTo,false,"myschool.net","myschool.net")
xhttp.send()
if (xhttp.status!=200) {
meaning = translateHttpHeader(xhttp.status);
hideFrame.document.clear();
hideFrame.document.write(xhttp.responseText)
longinfo.innerHTML="在测试服务器时<br>服务器送回以下HTTP标头!<br>"
longinfo.innerHTML+="<br><font color=red>HTTP "+xhttp.status+" "+xhttp.statusText+"</font> "
longinfo.innerHTML+="<font color=red><br>"+meaning+"</font> "
longinfo.innerHTML+="<br><br>此头表示当前请求的页面"+postTo+"可能有问题"
xhttp=null
window.status="错误"
return false;
}
else {
longinfo.innerHTML="指定的页面存在而且工作正常."
}
}
catch (e) {
longinfo.innerHTML="无法连接到指定的服务器:"+postTo+",或发生DNS错误"
longinfo.innerHTML+="<br>"+e.message+"<br><br>请确认您的网络连接。"
xhttp=null
window.status="错误"
return false;
}
window.status = "完毕"
}
function go() {
postTo = URL.value;
Method = sendMethod.value;
postTo.replace("\\","/")
if (postTo.indexOf("http://")==-1) {postTo = "http://"+postTo}
if (postTo.length >225) {longinfo.innerHTML = "URL过长,可能会造成错误。";URL.value="";return false}
window.status="正在使用"+Method+"方法测试:" + postTo +" 稍等..."
postRequest(postTo,Method)
}
</script>
</head>
<body>
请输入测试信息:<br>
URL:http://<input type=text id=URL size=100><br>
方法:<select id=sendMethod><option value="GET">GET</option><option value="POST">POST</option></select><Br>
<input type=button onclick=go() value=开始测试><hr>
<div id=longinfo>请输入需要测试的地址。</div>
<iframe id=hideFrame style="display:none"></iframe>
</body>
</html>
评论: 0 | 引用: 0 | 查看次数: 537
发表评论