Export (0) Print
Expand All

HttpWebResponse.Method Property

Gets the method that is used to return the response.

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

public virtual string Method { get; }

Property Value

Type: System.String
A string that contains the HTTP method that is used to return the response.

ExceptionCondition
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. However, only GET and POST methods are currently supported.



      // HttpWebRequest and HttpWebResponse are members of the 
      // RequestState class defined for this sample


      // Need to subtitute with a URI that works
        Uri url = new Uri("http://www.contoso.com");

        try 
 		    {	
            // Creates an HttpWebRequest for the specified URL. 
				    HttpWebRequest myHttpWebRequest1 = (HttpWebRequest)WebRequest.Create(url); 

            // Create an instance of the RequestState and assign the previous myHttpWebRequest1
            // object to it's request field.  
            RequestState myRequestState = new RequestState();  
            myRequestState.request = myHttpWebRequest1;

            // Start the asynchronous request.
            IAsyncResult result=
              (IAsyncResult) myHttpWebRequest1.BeginGetResponse(new AsyncCallback(RespCallback),myRequestState);

            allDone.WaitOne();

            outputBlock.Text += "The following method was used: ";
            outputBlock.Text += myRequestState.response.Method;
            outputBlock.Text += "\n";     

            // Release the HttpWebResponse resource.
            myRequestState.response.Close();
        }
		    catch(WebException e) 
		    {
		        outputBlock.Text += "\nException raised!\n";
            outputBlock.Text += "Message: ";
            outputBlock.Text += e.Message;
            outputBlock.Text += "\nStatus: ";
            outputBlock.Text += e.Status;
            outputBlock.Text += "\n";
        }
		    catch(Exception e)
			  {
            outputBlock.Text += "\nException raised!\n";
            outputBlock.Text += "\nMessage: ";
            outputBlock.Text += e.Message;
            outputBlock.Text += "\n";
			  }
	  }
	
	  private static void RespCallback(IAsyncResult asynchronousResult)
    {  
        try
        {
            // State of request is asynchronous.
            RequestState myRequestState=(RequestState) asynchronousResult.AsyncState;
            HttpWebRequest myHttpWebRequest2=myRequestState.request;
            myRequestState.response = (HttpWebResponse) myHttpWebRequest2.EndGetResponse(asynchronousResult);
        }
        catch(WebException e)
		    {
            // need to handle exception here
        }
    }


Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Windows Phone OS 7.0

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Community Additions

ADD
Show:
© 2014 Microsoft