다음을 통해 공유


HttpWebRequest.HaveResponse Property

Microsoft Silverlight will reach end of support after October 2021. Learn more.

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)

Syntax

'Declaration
Public Overridable ReadOnly Property HaveResponse As Boolean
public virtual bool HaveResponse { get; }

Property Value

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

Exceptions

Exception Condition
NotImplementedException

This property is not implemented.

Remarks

If an application implements a custom WebRequest class and does not override the HaveResponse property, then the NotImplementedException is thrown.

Examples

      try
      {      

        // Change this Uri to a public server
        System.Uri myUri = new Uri("https://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";
      }

Version Information

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

Platforms

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