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.

  NameDescription
Protected methodSupported by Portable Class LibraryWebResponse()Initializes a new instance of the WebResponse class.
Protected methodWebResponse(SerializationInfo, StreamingContext)Initializes a new instance of the WebResponse class from the specified instances of the SerializationInfo and StreamingContext classes.
Top

  NameDescription
Public propertySupported by Portable Class LibraryContentLengthWhen overridden in a descendant class, gets or sets the content length of data being received.
Public propertySupported by Portable Class LibraryContentTypeWhen overridden in a derived class, gets or sets the content type of the data being received.
Public propertySupported by Portable Class LibraryHeadersWhen overridden in a derived class, gets a collection of header name-value pairs associated with this request.
Public propertyIsFromCacheGets a Boolean value that indicates whether this response was obtained from the cache.
Public propertyIsMutuallyAuthenticatedGets a Boolean value that indicates whether mutual authentication occurred.
Public propertySupported by Portable Class LibraryResponseUriWhen overridden in a derived class, gets the URI of the Internet resource that actually responded to the request.
Public propertySupported by Portable Class LibrarySupportsHeaders
Top

  NameDescription
Public methodCloseWhen overridden by a descendant class, closes the response stream.
Public methodCreateObjRefCreates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object. (Inherited from MarshalByRefObject.)
Public methodSupported by Portable Class LibraryDispose()
Protected methodSupported by Portable Class LibraryDispose(Boolean)
Public methodSupported by Portable Class LibraryEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodSupported by Portable Class LibraryFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodSupported by Portable Class LibraryGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodGetLifetimeServiceRetrieves the current lifetime service object that controls the lifetime policy for this instance. (Inherited from MarshalByRefObject.)
Protected methodGetObjectDataInfrastructure. Populates a SerializationInfo with the data that is needed to serialize the target object.
Public methodSupported by Portable Class LibraryGetResponseStreamWhen overridden in a descendant class, returns the data stream from the Internet resource.
Public methodSupported by Portable Class LibraryGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodInitializeLifetimeServiceObtains a lifetime service object to control the lifetime policy for this instance. (Inherited from MarshalByRefObject.)
Protected methodSupported by Portable Class LibraryMemberwiseClone()Creates a shallow copy of the current Object. (Inherited from Object.)
Protected methodMemberwiseClone(Boolean)Creates a shallow copy of the current MarshalByRefObject object. (Inherited from MarshalByRefObject.)
Public methodSupported by Portable Class LibraryToStringReturns a string that represents the current object. (Inherited from Object.)
Top

  NameDescription
Explicit interface implemetationPrivate methodIDisposable.DisposeInfrastructure. When overridden in a derived class, releases all resources used by the WebResponse.
Explicit interface implemetationPrivate methodISerializable.GetObjectDataInfrastructure. 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.
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft