HttpWebResponse.Method HttpWebResponse.Method HttpWebResponse.Method HttpWebResponse.Method Property

Definition

Ruft die zum Zurückgeben der Antwort verwendete Methode ab.Gets the method that is used to return the response.

public:
 virtual property System::String ^ Method { System::String ^ get(); };
public virtual string Method { get; }
member this.Method : string
Public Overridable ReadOnly Property Method As String

Eigenschaftswert

Eine Zeichenfolge mit der zum Zurückgeben der Antwort verwendeten HTTP-Methode.A string that contains the HTTP method that is used to return the response.

Ausnahmen

Die aktuelle Instanz wurde verworfen.The current instance has been disposed.

Beispiele

Das folgende Beispiel überprüft die Zeichenfolge in Method, um zu bestimmen, die Http-Methode, die vom Webserver aufgerufen.The following example checks the string contained in Method, to determine the Http method invoked by the Web server.

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 occurred : {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 occurred : {0}",e.Status); 
          }
	catch(Exception e)
		{
			Console.WriteLine("\nThe following Exception was raised : {0}",e.Message);
		}
}
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 occurred : {0}", e.Status)
  Catch e As Exception
      Console.WriteLine(ControlChars.NewLine + "The following exception was raised : {0}", e.Message)
  End Try

Hinweise

Method Gibt die Methode, die zum Zurückgeben der Antwort verwendet wird.Method returns the method that is used to return the response. Allgemeine HTTP-Methoden sind GET, HEAD, POST, PUT und DELETE.Common HTTP methods are GET, HEAD, POST, PUT, and DELETE.

Gilt für: