检测远程文件是否存在
时间:2009-06-22 13:00:00
代码'###########
'检测远程文件是否存在
'###########
function CheckURL(byval A_strUrl)
set XMLHTTP = Server.CreateObject("Microsoft.XMLHTTP")
XMLHTTP.open "HEAD",A_strUrl,false
XMLHTTP.send()
CheckURL=(XMLHTTP.status=200)
set XMLHTTP = nothing
end function
if CheckURL(DownLoadUrl) then
do
else
do other...
end if
XMLHTTP检测远程文件存在与否
<%
response.write "检查是否开机<br>"
on error resume next
set xml=Server.createobject("Microsoft.XMLHTTP")
xml.open "get","http://www.hao114.com/ss.mdb",false
xml.send
ints=xml.status
strs=xml.statustext
if isnumeric(ints) then
if ints=12007 or strs="Unknown" then
response.write "地址出错<br>"
end if
if ints=404 then
response.write "找不到文件<br>"
else
response.write "地址正确<br>"
end if
end if
if response.buffer then
response.flush
end if
%>
<html>
<head>
</head>
<script language="vbscript">
function bytes2BSTR(vIn)
strReturn = ""
For i = 1 To LenB(vIn)
ThisCharCode = AscB(MidB(vIn,i,1))
If ThisCharCode < &H80 Then
strReturn = strReturn & Chr(ThisCharCode)
Else
NextCharCode = AscB(MidB(vIn,i+1,1))
strReturn = strReturn & Chr (CLng(ThisCharCode) * &H100 + CInt(NextCharCode))
i = i + 1
End If
Next
bytes2BSTR = strReturn
End function
function CheckUrl(url)
set oSend=createobject("Microsoft.XMLHTTP")
SourceCode = oSend.open ("GET",url,false)
oSend.send()
if instr(bytes2BSTR(oSend.responseBody),"Not Found")<>0 then
msgbox "此文件不存在"
else
msgbox "此文件存在"
end if
End function
</script>
<input name="myurl" id="myurl" type="textfield" value="">
<input type="button" onclick="CheckUrl(myurl.value)" value="检 测">
</html>
Function testURL(url)
Dim httpxml
Set httpxml = CreateObject("msxml2.XMLHTTP")
httpxml.open "HEAD",url,False
httpxml.send
If httpxml.status = 200 Then
testURL = 1
Else
testURL = 0
End If
Set httpxml = Nothing
End Function
if testurl("http://www.hao114.com/index.htm")=0 then
response.write"页面不存在"
else
response.write"页面存在"
end if