Export (0) Print
Expand All

WebException.Status Property

Gets the status of the response.

Namespace:  System.Net
Assembly:  System (in System.dll)

'Declaration
Public ReadOnly Property Status As WebExceptionStatus
'Usage
Dim instance As WebException 
Dim value As WebExceptionStatus 

value = instance.Status

Property Value

Type: System.Net.WebExceptionStatus
One of the WebExceptionStatus values.

The Status property indicates the reason for the WebException.

The value of Status is one of the WebExceptionStatus values.

The following example checks the Status property and prints to the console the StatusCode and StatusDescription of the underlying HttpWebResponse instance.

Try 
     'Create a web request for an invalid site. Substitute the "invalid site" strong in the Create call with a invalid name. 
     Dim myHttpWebRequest As HttpWebRequest = CType(WebRequest.Create("invalid site"), HttpWebRequest)

     'Get the associated response for the above request. 
     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
try {
   // Create a web request for an unknown server (this raises the WebException).
   HttpWebRequest* myHttpWebRequest =
      dynamic_cast<HttpWebRequest*> (WebRequest::Create(S"http://unknown.unknown.com"));

   // Get the associated response for the above request.
   HttpWebResponse* myHttpWebResponse =
      dynamic_cast<HttpWebResponse*> (myHttpWebRequest->GetResponse());
   myHttpWebResponse->Close();
} catch (WebException* e) {
   Console::WriteLine(S"This program is expected to throw WebException on successful run. \n\nException Message : {0}", e->Message);
   if (e->Status == WebExceptionStatus::ProtocolError) {
      Console::WriteLine(S"Status Code : {0}", __box((dynamic_cast<HttpWebResponse*>(e->Response))->StatusCode));
      Console::WriteLine(S"Status Description : {0}",
         (dynamic_cast<HttpWebResponse*>(e->Response))->StatusDescription);
   }

} catch (Exception* e) {
   Console::WriteLine(e->Message);
}

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 3.5, 2.0, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft