asp代码,如何用asp代码判断网页是否能正常打开,也就是说既不是404错误,也不是301跳转,是正常的网页?
答案:2 悬赏:0 手机版
解决时间 2021-01-03 01:33
- 提问者网友:書生途
- 2021-01-02 22:28
就是一个网页,网址文件,如何判断这个网址是正常的,我觉得应该用http状态返回值判断,也就是返回值200是正常的,但是不会编写这段代码。不知道各位高手是否有什么高见
最佳答案
- 五星知识达人网友:你可爱的野爹
- 2021-01-06 23:28
<html>
<head>
<title> 利用XMLHTTP检测URL及探测服务器信息 </title>
<META http-equiv=Content-Type content= "text/html; charset=gb2312 ">
<meta name= "Generator " content= "EditPlus ">
<meta name= "Author " content= "JnKc ">
<meta name= "Keywords " content= " ">
</head>
<body>
请输入URL: <input type= "text " id= "jnkcInput " value= "http:// " size= "40 "> <button id= "chk "> 检测 </button>
<div id= "jnkc_show "> </div>
<SCRIPT LANGUAGE= "VBScript ">
Dim i,jnkcUrl,jnkcHTML,jnkcStatus,jnkcServer
Function chk_onClick()
jnkcUrl = jnkcInput.value
Call GetDetail
i = i+1
jnkc_show.innerHTML = " <hr> <pre> <font color=red> " & i & "、 " & jnkcUrl & " </font> <br> " & jnkcStatus & " </pre> " & jnkc_show.innerHTML
End Function
Dim jnkcXMLHTTP
Sub GetDetail
Set jnkcXMLHTTP = CreateObject( "Microsoft.XMLHTTP ")
jnkcXMLHTTP.OnReadyStateChange = GetRef( "GetStatus ")
jnkcXMLHTTP.Open "GET ", jnkcUrl, False
On Error Resume Next
jnkcXMLHTTP.Send
Set jnkcXMLHTTP = Nothing
End Sub
Sub GetStatus
If jnkcXMLHTTP.ReadyState <> 4 Then
Exit Sub
End If
If jnkcXMLHTTP.Status = 404 Then
jnkcStatus = "该网页不存在! "
ElseIf jnkcXMLHTTP.Status < 200 Then
jnkcStatus = "客户端错误,信息: " & CStr(jnkcXMLHTTP.Status) & " " & jnkcXMLHTTP.StatusText
ElseIf jnkcXMLHTTP.Status < 300 Then
jnkcStatus = "成功,该网页能访问。 "
ElseIf jnkcXMLHTTP.Status < 400 Then
jnkcStatus = "重定向,信息: " & CStr(jnkcXMLHTTP.Status) & " " & jnkcXMLHTTP.StatusText
ElseIf jnkcXMLHTTP.Status < 500 Then
jnkcStatus = "客户端错误,信息: " & CStr(jnkcXMLHTTP.Status) & " " & jnkcXMLHTTP.StatusText
ElseIf jnkcXMLHTTP.Status < 600 Then
jnkcStatus = "服务器错误,信息: " & CStr(jnkcXMLHTTP.Status) & " " & jnkcXMLHTTP.StatusText
Else
jnkcStatus = "域名不可用或网络连接错误,信息: " & CStr(jnkcXMLHTTP.Status) & " " & jnkcXMLHTTP.StatusText
End If
If jnkcXMLHTTP.Status < 600 Then Call GetServer
End Sub
Sub GetServer
jnkcServer = jnkcXMLHTTP.GetResponseHeader( "Server ")
If jnkcServer <> " " Then
jnkcStatus = jnkcStatus & " <br> HTTP服务器: " & jnkcServer
End If
jnkcStatus = " <b> " & jnkcStatus & " </b> <br> 所有反馈信息: <br> "& jnkcXMLHTTP.GetAllResponseHeaders
End Sub
</SCRIPT>
</body>
</html>
<head>
<title> 利用XMLHTTP检测URL及探测服务器信息 </title>
<META http-equiv=Content-Type content= "text/html; charset=gb2312 ">
<meta name= "Generator " content= "EditPlus ">
<meta name= "Author " content= "JnKc ">
<meta name= "Keywords " content= " ">
</head>
<body>
请输入URL: <input type= "text " id= "jnkcInput " value= "http:// " size= "40 "> <button id= "chk "> 检测 </button>
<div id= "jnkc_show "> </div>
<SCRIPT LANGUAGE= "VBScript ">
Dim i,jnkcUrl,jnkcHTML,jnkcStatus,jnkcServer
Function chk_onClick()
jnkcUrl = jnkcInput.value
Call GetDetail
i = i+1
jnkc_show.innerHTML = " <hr> <pre> <font color=red> " & i & "、 " & jnkcUrl & " </font> <br> " & jnkcStatus & " </pre> " & jnkc_show.innerHTML
End Function
Dim jnkcXMLHTTP
Sub GetDetail
Set jnkcXMLHTTP = CreateObject( "Microsoft.XMLHTTP ")
jnkcXMLHTTP.OnReadyStateChange = GetRef( "GetStatus ")
jnkcXMLHTTP.Open "GET ", jnkcUrl, False
On Error Resume Next
jnkcXMLHTTP.Send
Set jnkcXMLHTTP = Nothing
End Sub
Sub GetStatus
If jnkcXMLHTTP.ReadyState <> 4 Then
Exit Sub
End If
If jnkcXMLHTTP.Status = 404 Then
jnkcStatus = "该网页不存在! "
ElseIf jnkcXMLHTTP.Status < 200 Then
jnkcStatus = "客户端错误,信息: " & CStr(jnkcXMLHTTP.Status) & " " & jnkcXMLHTTP.StatusText
ElseIf jnkcXMLHTTP.Status < 300 Then
jnkcStatus = "成功,该网页能访问。 "
ElseIf jnkcXMLHTTP.Status < 400 Then
jnkcStatus = "重定向,信息: " & CStr(jnkcXMLHTTP.Status) & " " & jnkcXMLHTTP.StatusText
ElseIf jnkcXMLHTTP.Status < 500 Then
jnkcStatus = "客户端错误,信息: " & CStr(jnkcXMLHTTP.Status) & " " & jnkcXMLHTTP.StatusText
ElseIf jnkcXMLHTTP.Status < 600 Then
jnkcStatus = "服务器错误,信息: " & CStr(jnkcXMLHTTP.Status) & " " & jnkcXMLHTTP.StatusText
Else
jnkcStatus = "域名不可用或网络连接错误,信息: " & CStr(jnkcXMLHTTP.Status) & " " & jnkcXMLHTTP.StatusText
End If
If jnkcXMLHTTP.Status < 600 Then Call GetServer
End Sub
Sub GetServer
jnkcServer = jnkcXMLHTTP.GetResponseHeader( "Server ")
If jnkcServer <> " " Then
jnkcStatus = jnkcStatus & " <br> HTTP服务器: " & jnkcServer
End If
jnkcStatus = " <b> " & jnkcStatus & " </b> <br> 所有反馈信息: <br> "& jnkcXMLHTTP.GetAllResponseHeaders
End Sub
</SCRIPT>
</body>
</html>
全部回答
- 1楼网友:酒安江南
- 2021-01-07 00:28
放在需要跳转部分的文件,一般是首页、列表页、文章页,把里面的代码全部替换成301永久重定向代码即可
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯