如何检查网址是否存在

如何检查网址是否存在

本文介绍了如何检查网址是否存在?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  Dim  urlexist  As  整数 =  0  
Dim urlDoesNotExist 作为 整数 = 0
对于 每个行在 TextBox1.Text.Split(Environment.NewLine)
Dim url 作为 新系统.Uri(line)
Dim req As System.Net.WebRequest
req = System.Net.WebRequest.Create(url)
Dim resp As System.Net。 WebResponse
尝试
resp = req.GetResponse()
resp.Close()
req = 没什么
urlexist = urlexist + 1
' MsgBox(找到网站!)
Catch ex As Exception
req = Nothing
urlDoesNotExist = urlDoesNotExist + 1
MsgBox(未找到网站。检查网址和互联网连接)
Button1.Text = urlDoesNotExist + 1
返回
结束 尝试
下一步
MsgBox( 存在是,urlexist)
MsgBox( 不存在是,urlDoesNotExist)





我的尝试:



此循环在2之后停止为什么?现在我不知道这里出现了什么问题

解决方案

Dim urlexist As Integer = 0
     Dim urlDoesNotExist As Integer = 0
     For Each line In TextBox1.Text.Split(Environment.NewLine)
         Dim url As New System.Uri(line)
         Dim req As System.Net.WebRequest
         req = System.Net.WebRequest.Create(url)
         Dim resp As System.Net.WebResponse
         Try
             resp = req.GetResponse()
             resp.Close()
             req = Nothing
             urlexist = urlexist + 1
             'MsgBox("Website Found!")
         Catch ex As Exception
             req = Nothing
             urlDoesNotExist = urlDoesNotExist + 1
             '   MsgBox("Website not found. Check the url and internet connection")
             Button1.Text = urlDoesNotExist + 1
             Return
         End Try
     Next
     MsgBox("exist is ", urlexist)
     MsgBox("non-exist is ", urlDoesNotExist)



What I have tried:

this loop stops after 2 why ? now i don't under stand what went wrong in this

解决方案


这篇关于如何检查网址是否存在?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-26 11:56