HttpWebRequest.HaveResponse Property
[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]
Gets a value that indicates whether a response has been received from an Internet resource.
Assembly: System.Net (in System.Net.dll)
| Exception | Condition |
|---|---|
| NotImplementedException | This property is not implemented. |
If an application implements a custom WebRequest class and does not override the HaveResponse property, then the NotImplementedException is thrown.
try
{
// Change this Uri to a public server
System.Uri myUri = new Uri("http://www.contoso.com");
// Create a 'HttpWebRequest' object.
HttpWebRequest myHttpWebRequest1=(HttpWebRequest)WebRequest.Create(myUri);
// 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);
// Suspend the thread for a bit
Thread.Sleep(200);
// Test the 'HaveResponse' property
outputBlock.Text += "HttpWebRequest.HaveResponse: ";
if (myHttpWebRequest1.HaveResponse)
outputBlock.Text += "True\n";
else
outputBlock.Text += "False\n";
allDone.WaitOne();
// 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";
}
Show: