WebException.Response Property gets the response that the remote host returned. : WebException « Network Remote « VB.Net






WebException.Response Property gets the response that the remote host returned.

 
Imports System.IO
Imports System.Net
Imports System.Text

public class MainClass
   Shared Sub Main()
         Try
             Dim myHttpWebRequest As HttpWebRequest = CType(WebRequest.Create("invalid site"), HttpWebRequest)
             Dim myHttpWebResponse As HttpWebResponse = CType(myHttpWebRequest.GetResponse(), HttpWebResponse)
             myHttpWebResponse.Close()
         Catch e As WebException
             Console.WriteLine(e.Message)
             If e.Status = WebExceptionStatus.ProtocolError Then
                 Console.WriteLine("Status Code : {0}", CType(e.Response, HttpWebResponse).StatusCode)
                 Console.WriteLine("Status Description : {0}", CType(e.Response, HttpWebResponse).StatusDescription)
             End If
        
        Catch e As Exception
             Console.WriteLine(e.Message)
        End Try
    End Sub 
End Class

   
  








Related examples in the same category