Posted in 面试题 onNovember 10, 2013
利用XMLHTTP检测或监测URL,确认某个网页或网站是否可以正常访问?
如何利用XMLHTTP探测服务器信息?检测网页
Microsoft XML Version 2.0 (C:WinntSystem32msxml.dll)
Option Explicit
Private XmlHTTP As New XMLHTTPRequest
Private vUrl As String
Private vNumber As String
Private vDescription As String
Private vSource As String
Public Sub Connect()
On Error GoTo ErrorHandle:
XmlHTTP.Open \”Get\”, Url, False
XmlHTTP.send
ErrorHandle:
Call GetErrorHeadle(XmlHTTP)
End Sub
Private Sub GetErrorHeadle(ByRef XmlHTTP As XMLHTTPRequest)
If XmlHTTP.readyState 4 Then
Exit Sub
End If
If XmlHTTP.Status = 404 Then
Number = \”404\”
Description = \”该网页不存在\”
ElseIf XmlHTTP.Status Number = XmlHTTP.Status
Description = \”客户端错误,信息:\” & CStr(XmlHTTP.Status) & \” \” & XmlHTTP.statusText
ElseIf XmlHTTP.Status Number = XmlHTTP.Status
Description = \”成功,该网页能访问。\”
ElseIf XmlHTTP.Status Number = XmlHTTP.Stauts
Description = \”重定向,信息:\” & CStr(XmlHTTP.Status) & \” \” & XmlHTTP.statusText
ElseIf XmlHTTP.Status Number = XmlHTTP.Status
Description = \”客户端错误,信息:\” & CStr(XmlHTTP.Status) & \” \” & XmlHTTP.statusText
ElseIf XmlHTTP.Status Number = XmlHTTP.Status
Description = \”服务器错误,信息:\” & CStr(XmlHTTP.Status) & \” \” & XmlHTTP.statusText
Else
Number = XmlHTTP.Status
Description = \”域名不可用或网络连接错误,信息:\” & CStr(XmlHTTP.Status) & \” \” & XmlHTTP.statusText
End If
If XmlHTTP.Status End Sub
Private Sub GetHTTPServer()
Dim XmlServer As String
XmlServer = XmlHTTP.getResponseHeader(\”Server\”)
If XmlServer \”\” Then
Source = Source & \”HTTP服务器:\” & XmlServer
End If
Source = Source & \”所有反馈信息:\” & XmlHTTP.getAllResponseHeaders
End Sub
Public Property Get Number() As String
Number = vNumber
End Property
Public Property Let Number(ByVal Val As String)
vNumber = Val
End Property
Public Property Get Description() As String
Description = vDescription
End Property
Public Property Let Description(ByVal Val As String)
vDescription = Val
End Property
Public Property Get Url() As String
Url = vUrl
End Property
Public Property Let Url(ByVal Val As String)
vUrl = Val
End Property
Public Property Get Source() As String
Source = vSource
End Property
Private Property Let Source(ByVal Val As String)
vSource = Val
End Property
如何利用XMLHTTP探测服务器信息?检测网页
Microsoft XML Version 2.0 (C:WinntSystem32msxml.dll)
Option Explicit
Private XmlHTTP As New XMLHTTPRequest
Private vUrl As String
Private vNumber As String
Private vDescription As String
Private vSource As String
Public Sub Connect()
On Error GoTo ErrorHandle:
XmlHTTP.Open \”Get\”, Url, False
XmlHTTP.send
ErrorHandle:
Call GetErrorHeadle(XmlHTTP)
End Sub
Private Sub GetErrorHeadle(ByRef XmlHTTP As XMLHTTPRequest)
If XmlHTTP.readyState 4 Then
Exit Sub
End If
If XmlHTTP.Status = 404 Then
Number = \”404\”
Description = \”该网页不存在\”
ElseIf XmlHTTP.Status Number = XmlHTTP.Status
Description = \”客户端错误,信息:\” & CStr(XmlHTTP.Status) & \” \” & XmlHTTP.statusText
ElseIf XmlHTTP.Status Number = XmlHTTP.Status
Description = \”成功,该网页能访问。\”
ElseIf XmlHTTP.Status Number = XmlHTTP.Stauts
Description = \”重定向,信息:\” & CStr(XmlHTTP.Status) & \” \” & XmlHTTP.statusText
ElseIf XmlHTTP.Status Number = XmlHTTP.Status
Description = \”客户端错误,信息:\” & CStr(XmlHTTP.Status) & \” \” & XmlHTTP.statusText
ElseIf XmlHTTP.Status Number = XmlHTTP.Status
Description = \”服务器错误,信息:\” & CStr(XmlHTTP.Status) & \” \” & XmlHTTP.statusText
Else
Number = XmlHTTP.Status
Description = \”域名不可用或网络连接错误,信息:\” & CStr(XmlHTTP.Status) & \” \” & XmlHTTP.statusText
End If
If XmlHTTP.Status End Sub
Private Sub GetHTTPServer()
Dim XmlServer As String
XmlServer = XmlHTTP.getResponseHeader(\”Server\”)
If XmlServer \”\” Then
Source = Source & \”HTTP服务器:\” & XmlServer
End If
Source = Source & \”所有反馈信息:\” & XmlHTTP.getAllResponseHeaders
End Sub
Public Property Get Number() As String
Number = vNumber
End Property
Public Property Let Number(ByVal Val As String)
vNumber = Val
End Property
Public Property Get Description() As String
Description = vDescription
End Property
Public Property Let Description(ByVal Val As String)
vDescription = Val
End Property
Public Property Get Url() As String
Url = vUrl
End Property
Public Property Let Url(ByVal Val As String)
vUrl = Val
End Property
Public Property Get Source() As String
Source = vSource
End Property
Private Property Let Source(ByVal Val As String)
vSource = Val
End Property
如何利用XMLHTTP检测URL及探测服务器信息
声明:登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述。
Tags in this post...
Reply on: @reply_date@
@reply_contents@