webclient file exists

VNote 2017.11.08 21:37:02 *: Imports System.Net

Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim url As New System.Uri("http://localhost/1.txt")
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
MsgBox("Website Found!")
Catch ex As Exception
req = Nothing
End Try
End Sub
End Class

Imports System.Net

Public Class Form1

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Dim request = DirectCast(WebRequest.Create("http://localhost/11.txt"), WebRequest)

        Try
            Dim response As WebResponse = DirectCast(request.GetResponse(), WebResponse)
            MsgBox("exist")
        Catch ex As WebException

            Dim response As WebResponse = DirectCast(ex.Response, WebResponse)
            MsgBox("no exist")
        End Try
    End Sub
End Class