System.Net.WebResponse Class

Provides a response from a Uniform Resource Identifier (URI). This is an abstract class.

See Also: WebResponse Members

Syntax

public abstract class WebResponse : MarshalByRefObject, IDisposable, System.Runtime.Serialization.ISerializable

Remarks

The System.Net.WebResponse class is the abstract base class from which protocol-specific response classes are derived. Applications can participate in request and response transactions in a protocol-agnostic manner using instances of the System.Net.WebResponse class while protocol-specific classes derived from System.Net.WebResponse carry out the details of the request.

Client applications do not create System.Net.WebResponse objects directly; they are created by calling the WebRequest.GetResponse method on a System.Net.WebRequest instance.

Thread Safety

All public static members of this type are safe for multithreaded operations. No instance members are guaranteed to be thread safe.

Example

The following example creates a System.Net.WebResponse instance from a System.Net.WebRequest .

C# Example

using System;
using System.Net;

public class WebResponseExample {

  public static void Main() {

    // Initialize the WebRequest.
    WebRequest myRequest =
      WebRequest.Create("http://www.contoso.com");

    // Return the response. 
    WebResponse myResponse = myRequest.GetResponse();

    // Code to use the WebResponse goes here.

    // Close the response to free resources.
    myResponse.Close();
  }
}

Requirements

Namespace: System.Net
Assembly: System (in System.dll)
Assembly Versions: 1.0.x.x, 1.0.5000.0, 2.0.0.0, 4.0.0.0