我的数据库中有大约40个值。我正在检查每个网址是否在线或离线。这是我正在使用的功能:
Public Function CheckAddress(ByVal URL As String) As Boolean
Try
Dim request As WebRequest = WebRequest.Create(URL)
Dim response As WebResponse = request.GetResponse()
Catch ex As Exception
Return False
End Try
Return True
End Function
但这需要花费太多时间。我们如何更快地加载页面?
答案 0 :(得分:0)
也许你可以通过HEAD方法检查标题:
Public Function CheckAddress(ByVal URL As String) As Boolean
Try
Dim request As WebRequest = WebRequest.Create(URL)
request.Method = "HEAD" ' only headers!
Dim response As WebResponse = request.GetResponse()
If response IsNot Nothing AndAlso _
response.Headers IsNot Nothing AndAlso _
response.Headers.count > 0
...
' check if you get anything
Return True
else
Return false
end if
Catch ex As Exception
Return False
End Try
End Function
这可能会更快。
答案 1 :(得分:0)
我向WebRequest添加了超时。像:
Dim request As WebRequest = WebRequest.Create(URL)
request.Timeout = 50