如何检查网站是否已启动?

时间:2016-01-17 22:06:49

标签: vb.net

我正在学习vb.net并且想知道如何检查网站,如果它已经启动,设置公共共享,如果它已关闭,则使用不同的公共共享?

我目前的代码为

Public Shared domain As String = "domain"

但是当我启动应用程序然后运行检查时,我很困惑如何检查网站。

---编辑这就是我现在所拥有的,

Dim URL As String = "https://www.personalblog.com"

Public Shared Function IsWebpageOnline(ByVal URL As String) As Boolean
    Try
        Dim req As WebRequest = WebRequest.Create(URL)
        Dim res As WebResponse = req.GetResponse()
    Catch ex As Exception
        Return False
    End Try
    Return True
End Function

 If IsWebpageOnline = 1 Then
Public Shared domain As String = "blog.com"
 Else
Public Shared domain As String = "backupblog.com"
 End If

1 个答案:

答案 0 :(得分:-1)

您可以使用此功能检查网页是否在线。

 Public Shared Function IsWebpageOnline(ByVal URL As String) As Boolean
       Try
            Dim req As WebRequest = WebRequest.Create(URL)
            Dim res As WebResponse = req.GetResponse()
       Catch ex As Exception
            Console.WriteLine(ex.Message)
            Return False
       End Try
    Return True
 End Function

它会尝试向Web服务器发出get请求,然后返回bool值

但我必须建议,尽早切换到C#。