达人出手:web开发中需要用到的”检测一个链接是否有效“
[UseMoney=100]首先要引入两个需要用的命名空间Imports System.Net
Imports System.Net.Sockets
代码实现过程如下
Dim httpReq As HttpWebRequest = CType(WebRequest.Create("在此填上url"), HttpWebRequest), httpRes As HttpWebResponse
httpReq.AllowAutoRedirect = False
Try
httpRes = CType(httpReq.GetResponse(), HttpWebResponse)
If httpRes.StatusCode = HttpStatusCode.OK Then
'如果远程连接是打开的
'插入你的代码
httpRes.Close()
End If
Catch ex As WebException
'加入你的纠错代码
End Try
[/UseMoney]
[此贴子已经被作者于2005-12-8 21:53:13编辑过]