Export (0) Print
Expand All

HttpWebResponse.Method Property

Gets the method that is used to return the response.

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

public string Method { get; }
/** @property */
public String get_Method ()

public function get Method () : String

Not applicable.

Property Value

A string that contains the HTTP method that is used to return the response.

Exception typeCondition

ObjectDisposedException

The current instance has been disposed.

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

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 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

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

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft