Imports System
Imports System.Net
Namespace E
Public Class WebTest
Public Shared Sub Test(ByVal url As String)
Try
Dim wreq As WebRequest = WebRequest.Create(url)
Dim wresp As WebResponse = wreq.GetResponse
If TypeOf wresp Is HttpWebResponse Then
Dim hwresp As HttpWebResponse = CType(wresp, HttpWebResponse)
If hwresp.StatusCode = HttpStatusCode.OK Then
Console.WriteLine(url + " is working")
Else
Console.WriteLine(url + " has small problems: " + hwresp.StatusDescription)
End If
Else
Console.WriteLine(url + " is not a HTTP URL")
End If
Catch wex As WebException
If wex.Response Is Nothing Then
Console.WriteLine(url + " has big problems: " + wex.Message)
Else
If TypeOf wex.Response Is HttpWebResponse Then
Dim hwresp As HttpWebResponse = CType(wex.Response, HttpWebResponse)
If hwresp.StatusCode = HttpStatusCode.OK Then
Console.WriteLine(url + " is working")
Else
Console.WriteLine(url + " has small problems: " + hwresp.StatusDescription)
End If
Else
Console.WriteLine(url + " is not a HTTP URL")
End If
End If
End Try
End Sub
End Class
Class MainClass
Public Shared Sub Main(ByVal args As String())
WebTest.Test("
http://arne/index.html")
WebTest.Test("
http://arne/notexist.html")
WebTest.Test("
http://notexist/index.html")
End Sub
End Class
End Namespace