Export (0) Print
Expand All

HttpWebResponse.Method Property

Gets the method used to return the response.

[Visual Basic]
Public ReadOnly Property Method As String
[C#]
public string Method {get;}
[C++]
public: __property String* get_Method();
[JScript]
public function get Method() : String;

Property Value

A string containing the HTTP method used to return the response.

Exceptions

Exception Type Condition
ObjectDisposedException The current instance has been disposed.

Remarks

Method returns the method used to return the response. Common HTTP methods are GET, HEAD, POST, PUT, and DELETE.

Example

[Visual Basic, C#, C++] The following example checks the string contained in Method, to determine the Http method invoked by the Web server.

[Visual Basic] 
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

[C#] 
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);
    }
    }

[C++] 
try {
   // Creates an HttpWebRequest for the specified URL.
   HttpWebRequest* myHttpWebRequest =
      dynamic_cast<HttpWebRequest*>(WebRequest::Create(url));
   HttpWebResponse* myHttpWebResponse =
      dynamic_cast<HttpWebResponse*>(myHttpWebRequest->GetResponse());
   String* method ;
   method = myHttpWebResponse->Method;
   if (String::Compare(method, S"GET") == 0)
      Console::WriteLine(S"\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(S"\nWebException raised. The following error occured : {0}",
      __box(e->Status));
} catch (Exception* e) {
   Console::WriteLine(S"\nThe following Exception was raised : {0}",
      e->Message);
}
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework, Common Language Infrastructure (CLI) Standard

See Also

HttpWebResponse Class | HttpWebResponse Members | System.Net Namespace

Show:
© 2014 Microsoft