Freigeben über


WebException.Status-Eigenschaft

Ruft den Status der Antwort ab.

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

Syntax

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

value = instance.Status
public WebExceptionStatus Status { get; }
public:
property WebExceptionStatus Status {
    WebExceptionStatus get ();
}
/** @property */
public WebExceptionStatus get_Status ()
public function get Status () : WebExceptionStatus

Eigenschaftenwert

Einer der WebExceptionStatus-Werte.

Hinweise

Die Status-Eigenschaft gibt den Grund für die WebException an.

Der Wert von Status ist einer der WebExceptionStatus-Werte.

Beispiel

Im folgenden Beispiel wird die Status-Eigenschaft überprüft. Zudem werden StatusCode und StatusDescription der zugrunde liegenden HttpWebResponse-Instanz in der Konsole ausgegeben.

 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 invalid site. Substitute the "invalid site" strong in the Create call with a invalid name.
     HttpWebRequest myHttpWebRequest = (HttpWebRequest) WebRequest.Create("invalid site");

    // Get the associated response for the above request.
     HttpWebResponse myHttpWebResponse = (HttpWebResponse) myHttpWebRequest.GetResponse();
    myHttpWebResponse.Close();
}
catch(WebException e) {
    Console.WriteLine("This program is expected to throw WebException on successful run."+
                        "\n\nException Message :" + e.Message);
    if(e.Status == WebExceptionStatus.ProtocolError) {
        Console.WriteLine("Status Code : {0}", ((HttpWebResponse)e.Response).StatusCode);
        Console.WriteLine("Status Description : {0}", ((HttpWebResponse)e.Response).StatusDescription);
    }
}
catch(Exception e) {
    Console.WriteLine(e.Message);
}
try
{
   // Create a web request for an unknown server (this raises the WebException).
   HttpWebRequest^ myHttpWebRequest = (HttpWebRequest^)(WebRequest::Create( "http://unknown.unknown.com" ));
   
   // Get the associated response for the above request.
   HttpWebResponse^ myHttpWebResponse = (HttpWebResponse^)(myHttpWebRequest->GetResponse());
   myHttpWebResponse->Close();
}
catch ( WebException^ e ) 
{
   Console::WriteLine( "This program is expected to throw WebException on successful run." +
      "\n\nException Message : " + e->Message );
   if ( e->Status == WebExceptionStatus::ProtocolError )
   {
      Console::WriteLine( "Status Code: {0}", ( (HttpWebResponse^)(e->Response) )->StatusCode );
      Console::WriteLine( "Status Description: {0}", ( (HttpWebResponse^)(e->Response) )->StatusDescription );
   }
}
catch ( Exception^ e ) 
{
   Console::WriteLine( e->Message );
}
try {
    // Create a web request for an invalid site. Substitute the
    // "invalid site" strong in the Create call with a invalid name.
    HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.
        Create("invalid site");
    // Get the associated response for the above request.
    HttpWebResponse myHttpWebResponse =
        ( HttpWebResponse)myHttpWebRequest.GetResponse();
    myHttpWebResponse.Close();
}
catch (WebException e) {
    Console.WriteLine("This program is expected to throw WebException"
        + " on successful run." + "\n\nException Message :" 
        + e.get_Message());
    if (e.get_Status().Equals(WebExceptionStatus.ProtocolError)) {
        Console.WriteLine("Status Code : {0}", ((HttpWebResponse)(e.
            get_Response())).get_StatusCode());
        Console.WriteLine("Status Description : {0}",((HttpWebResponse)(
            e.get_Response())).get_StatusDescription());
    }
}

Plattformen

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Mobile für Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

.NET Compact Framework

Unterstützt in: 2.0, 1.0

Siehe auch

Referenz

WebException-Klasse
WebException-Member
System.Net-Namespace
WebExceptionStatus