所有方法都来自网上还未测试
1.JS方法
xmlhttp.open("HEAD", "http:://..../*.jpg",true);
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4) {
if (xmlhttp.status==200)
alert("URL Exists!")
else if (xmlhttp.status==404)
alert("URL doesnt exist! ")
2 .ASP
Function Getbody(Url)
On Error Resume Next
Set Retrieval = Createobject("Microsoft.Xmlhttp")
With Retrieval
.Open "Get", Url, False
.Send
IF .readyState=4 THEN
if .status=200 THEN
RESPONSE.Write("1")
elseif .status=404 THEN
RESPONSE.Write("2")
END IF
END IF
'Getbody = .Responsebody
End With
Set Retrieval = Nothing
End Function
Getbody("http://192.168.1.67/dictionary.htm")
3.ASP.NET
用WebClient去请求,然后判断请求结果..
Try
Cursor.Current = Cursors.Hand
Dim Filename As String = "zxerp.exe"
Dim DownUrl As String = "http://" & serverName & "/download/aaa/" & Filename
Dim myStringWebResource As String = DownUrl
Dim myWebClient As New WebClient()
myWebClient.DownloadFile(myStringWebResource, Application.StartupPath & "/csdn.gif")
myWebClient.Dispose()
Catch ex As Exception
MsgBox(Err.Description & " " & Err.Number, MsgBoxStyle.Critical + MsgBoxStyle.OKOnly, "提示")
Cursor.Current = Cursors.Default
Exit Sub
End Try
Cursor.Current = Cursors.Default
WebRequest的HEAD方法。不用下载文件的,快速
Private Function ResourceExists(ByVal URL As String) As Boolean
Dim wr As WebRequest = WebRequest.Create(URL)
Dim res As WebResponse
Try
res = wr.GetResponse
Return True
Catch ex As Exception
Return False
End Try
End Function
在.NET中利用XMLHTTP下载文件




























