HttpWebResponse.Method 속성

정의

응답을 반환하는 데 사용되는 메서드를 가져옵니다.

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

속성 값

String

응답을 반환하는 데 사용되는 HTTP 메서드를 포함하는 문자열입니다.

예외

현재 인스턴스가 삭제된 경우

예제

다음 예제에서는 웹 서버에서 Method호출하는 Http 메서드를 확인하기 위해 , 에 포함된 문자열을 확인합니다.

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

설명

Method 는 응답을 반환하는 데 사용되는 메서드를 반환합니다. 일반적인 HTTP 메서드는 GET, HEAD, POST, PUT 및 DELETE입니다.

적용 대상