Freigeben über


HttpWebResponse.Method-Eigenschaft

Ruft die zum Zurückgeben der Antwort verwendete Methode ab.

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

Syntax

'Declaration
Public ReadOnly Property Method As String
'Usage
Dim instance As HttpWebResponse
Dim value As String

value = instance.Method
public string Method { get; }
public:
property String^ Method {
    String^ get ();
}
/** @property */
public String get_Method ()
public function get Method () : String

Eigenschaftenwert

Eine Zeichenfolge mit der zum Zurückgeben der Antwort verwendeten HTTP-Methode.

Ausnahmen

Ausnahmetyp Bedingung

ObjectDisposedException

Die aktuelle Instanz wurde bereits verworfen.

Hinweise

Method gibt die zum Zurückgeben der Antwort verwendete Methode zurück. Häufig verwendete HTTP-Methoden sind GET, HEAD, POST, PUT und DELETE.

Beispiel

Im folgenden Beispiel wird die Zeichenfolge in Method überprüft, um die vom Webserver aufgerufene HTTP-Methode zu bestimmen.

Try
      Dim myHttpWebRequest As HttpWebRequest = CType(WebRequest.Create(url), HttpWebRequest)
      Dim myHttpWebResponse As HttpWebResponse = CType(myHttpWebRequest.GetResponse(), HttpWebResponse)
      Dim method As String
      method = myHttpWebResponse.Method
      If [String].Compare(method, "GET") = 0 Then
          Console.WriteLine(ControlChars.NewLine + "The GET method was successfully invoked on the following Web Server : {0}", myHttpWebResponse.Server)
      End If
      ' Releases the resources of the response.
      myHttpWebResponse.Close()
  Catch e As WebException
      Console.WriteLine(ControlChars.NewLine + "Exception Raised. The following error occured : {0}", e.Status)
  Catch e As Exception
      Console.WriteLine(ControlChars.NewLine + "The following exception was raised : {0}", e.Message)
  End Try
    try 
       {    
        // Creates an HttpWebRequest for the specified URL. 
            HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(url); 
            HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse(); 
            string method ;
            method = myHttpWebResponse.Method;
            if (String.Compare(method,"GET") == 0)
                Console.WriteLine("\nThe 'GET' method was successfully invoked on the following Web Server : {0}",
                                   myHttpWebResponse.Server);
            // Releases the resources of the response.
            myHttpWebResponse.Close();
      } 
    catch(WebException e) 
       {
            Console.WriteLine("\nWebException raised. The following error occured : {0}",e.Status); 
       }
    catch(Exception e)
        {
            Console.WriteLine("\nThe following Exception was raised : {0}",e.Message);
        }
}
try
{
   // Creates an HttpWebRequest for the specified URL.
   HttpWebRequest^ myHttpWebRequest = (HttpWebRequest^)( WebRequest::Create( url ) );
   HttpWebResponse^ myHttpWebResponse = (HttpWebResponse^)( myHttpWebRequest->GetResponse() );
   String^ method;
   method = myHttpWebResponse->Method;
   if ( String::Compare( method, "GET" ) == 0 )
   {
      Console::WriteLine( "\nThe 'GET' method was successfully invoked on the following Web Server : {0}",
         myHttpWebResponse->Server );
   }
   // Releases the resources of the response.
   myHttpWebResponse->Close();
}
catch ( WebException^ e ) 
{
   Console::WriteLine( "\nWebException raised. The following error occured : {0}", e->Status );
}
catch ( Exception^ e ) 
{
   Console::WriteLine( "\nThe following Exception was raised : {0}", e->Message );
}
    try {
        // Creates an HttpWebRequest for the specified URL. 
        HttpWebRequest myHttpWebRequest = (HttpWebRequest)
            WebRequest.Create(url);
        HttpWebResponse myHttpWebResponse = (HttpWebResponse)
            myHttpWebRequest.GetResponse();
        String method;
        method = myHttpWebResponse.get_Method();
        if (String.Compare(method, "GET") == 0) {
            Console.WriteLine("\nThe 'GET' method was successfully invoked "
                + "on the following Web Server : {0}", 
                myHttpWebResponse.get_Server());
        }

        // Releases the resources of the response.
        myHttpWebResponse.Close();
    }
    catch (WebException e) {
        Console.WriteLine("\nWebException raised. The following error "
            + "occured : {0}", e.get_Status());
    }
    catch (System.Exception e) {
        Console.WriteLine("\nThe following Exception was raised : {0}", 
            e.get_Message());
    }
} //GetPage

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

HttpWebResponse-Klasse
HttpWebResponse-Member
System.Net-Namespace