Export (0) Print
Expand All

HttpWebRequest.HaveResponse Property

Gets a value that indicates whether a response has been received from an Internet resource.

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

public virtual bool HaveResponse { get; }

Property Value

Type: System.Boolean
true if a response has been received; otherwise, false.

ExceptionCondition
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";
      }



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