0 out of 1 rated this helpful - Rate this topic

WebResponse Class

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

Namespace:  System.Net
Assembly:  System (in System.dll)
[SerializableAttribute]
public abstract class WebResponse : MarshalByRefObject, 
	ISerializable, IDisposable

The WebResponse type exposes the following members.

  Name Description
Protected method Supported by Portable Class Library WebResponse() Initializes a new instance of the WebResponse class.
Protected method WebResponse(SerializationInfo, StreamingContext) Initializes a new instance of the WebResponse class from the specified instances of the SerializationInfo and StreamingContext classes.
Top
  Name Description
Public property Supported by Portable Class Library ContentLength When overridden in a descendant class, gets or sets the content length of data being received.
Public property Supported by Portable Class Library ContentType When overridden in a derived class, gets or sets the content type of the data being received.
Public property Supported by Portable Class Library Headers When overridden in a derived class, gets a collection of header name-value pairs associated with this request.
Public property IsFromCache Gets a Boolean value that indicates whether this response was obtained from the cache.
Public property IsMutuallyAuthenticated Gets a Boolean value that indicates whether mutual authentication occurred.
Public property Supported by Portable Class Library ResponseUri When overridden in a derived class, gets the URI of the Internet resource that actually responded to the request.
Public property Supported by Portable Class Library SupportsHeaders
Top
  Name Description
Public method Close When overridden by a descendant class, closes the response stream.
Public method CreateObjRef Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object. (Inherited from MarshalByRefObject.)
Public method Supported by Portable Class Library Dispose()
Protected method Supported by Portable Class Library Dispose(Boolean)
Public method Supported by Portable Class Library Equals(Object) Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected method Supported by Portable Class Library Finalize Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public method Supported by Portable Class Library GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
Public method GetLifetimeService Retrieves the current lifetime service object that controls the lifetime policy for this instance. (Inherited from MarshalByRefObject.)
Protected method GetObjectData Infrastructure. Populates a SerializationInfo with the data that is needed to serialize the target object.
Public method Supported by Portable Class Library GetResponseStream When overridden in a descendant class, returns the data stream from the Internet resource.
Public method Supported by Portable Class Library GetType Gets the Type of the current instance. (Inherited from Object.)
Public method InitializeLifetimeService Obtains a lifetime service object to control the lifetime policy for this instance. (Inherited from MarshalByRefObject.)
Protected method Supported by Portable Class Library MemberwiseClone() Creates a shallow copy of the current Object. (Inherited from Object.)
Protected method MemberwiseClone(Boolean) Creates a shallow copy of the current MarshalByRefObject object. (Inherited from MarshalByRefObject.)
Public method Supported by Portable Class Library ToString Returns a string that represents the current object. (Inherited from Object.)
Top
  Name Description
Explicit interface implemetation Private method IDisposable.Dispose Infrastructure. When overridden in a derived class, releases all resources used by the WebResponse.
Explicit interface implemetation Private method ISerializable.GetObjectData Infrastructure. Populates a SerializationInfo instance with the data that is needed to serialize WebResponse.
Top

The 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 WebResponse class while protocol-specific classes derived from WebResponse carry out the details of the request.

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

The WebResponse class contains new members when it is used in a Portable Class Library project. For more information, see API Differences in Portable Class Library.

Notes to Inheritors

When you inherit from WebResponse, you must override the following members: ContentLength, ContentType, GetResponseStream, ResponseUri, and Headers.

The following example creates a WebResponse instance from a WebRequest.


// 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();



.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ