VB XMLHTTP使用方法

时间:2021-12-01 14:45:31

Private Function IsHearOK(URL As String) As Boolean
Dim XMLObject As Object, ReturnType As String
Set XMLObject = CreateObject("Microsoft.XMLHTTP")
XMLObject.Open "GET", URL, False
XMLObject.setRequestHeader "CONTENT-TYPE", "application/x-www-form-urlencoded"
XMLObject.setRequestHeader "Range", "bytes=1-255"
XMLObject.Send
If XMLObject.Status = 200 Or XMLObject.Status = 206 Then
ReturnType = XMLObject.getResponseHeader("CONTENT-TYPE")
If UCase(ReturnType) <> "TEXT/HTML" Then
IsHearOK = True
Else
IsHearOK = False
End If
Else
IsHearOK = False
End If
Set XMLObject = Nothing
End Function

Private Sub Command1_Click()
If IsHearOK("http://www.zzvips.com/test.exe") Then
MsgBox "ok"
Else
MsgBox "no"
End If
End Sub