HttpWebResponse.Method Property
[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]
Gets the method that is used to return the response.
Assembly: System.Net (in System.Net.dll)
Property Value
Type: System.StringA string that contains the HTTP method that is used to return the response.
| Exception | Condition |
|---|---|
| ObjectDisposedException | The current instance has been disposed. |
// 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
}
}
Show: