Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

WebResponse Class

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

Namespace:  System.Net
Assemblies:   System.Net.Requests (in System.Net.Requests.dll)
  System (in System.dll)

'Declaration
Public MustInherit Class WebResponse _
	Implements IDisposable

The WebResponse type exposes the following members.

  NameDescription
Protected methodSupported by Portable Class LibraryWebResponseInitializes 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 LibrarySupportsHeadersGets a value that indicates if headers are supported.
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 LibraryDisposeReleases the unmanaged resources used by the WebResponse object.
Protected methodDispose(Boolean)Releases the unmanaged resources used by the WebResponse object, and optionally disposes of the managed resources.
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 the default hash function. (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 LibraryMemberwiseCloneCreates 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.

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. 
        Dim myRequest As WebRequest = WebRequest.Create("http://www.contoso.com")

        ' Return the response.  
        Dim myResponse As WebResponse = myRequest.GetResponse()

        ' Code to use the WebResponse goes here. 
        ' Close the response to free resources.
        myResponse.Close()

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library

Supported in: Windows Phone 8.1

Supported in: Windows Phone Silverlight 8.1

Supported in: Windows Phone Silverlight 8

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Show:
© 2015 Microsoft