Edit

Share via


HttpWebResponse Class

Definition

Provides an HTTP-specific implementation of the WebResponse class.

public ref class HttpWebResponse : System::Net::WebResponse
public ref class HttpWebResponse : System::Net::WebResponse, System::Runtime::Serialization::ISerializable
public ref class HttpWebResponse : System::Net::WebResponse, IDisposable, System::Runtime::Serialization::ISerializable
public class HttpWebResponse : System.Net.WebResponse
public class HttpWebResponse : System.Net.WebResponse, System.Runtime.Serialization.ISerializable
[System.Serializable]
public class HttpWebResponse : System.Net.WebResponse, IDisposable, System.Runtime.Serialization.ISerializable
[System.Serializable]
public class HttpWebResponse : System.Net.WebResponse, System.Runtime.Serialization.ISerializable
type HttpWebResponse = class
    inherit WebResponse
type HttpWebResponse = class
    inherit WebResponse
    interface ISerializable
[<System.Serializable>]
type HttpWebResponse = class
    inherit WebResponse
    interface ISerializable
    interface IDisposable
[<System.Serializable>]
type HttpWebResponse = class
    inherit WebResponse
    interface ISerializable
Public Class HttpWebResponse
Inherits WebResponse
Public Class HttpWebResponse
Inherits WebResponse
Implements ISerializable
Public Class HttpWebResponse
Inherits WebResponse
Implements IDisposable, ISerializable
Inheritance
HttpWebResponse
Inheritance
Attributes
Implements

Examples

The following example returns an HttpWebResponse from an HttpWebRequest.

HttpWebRequest^ HttpWReq = dynamic_cast<HttpWebRequest^>(WebRequest::Create( "http://www.contoso.com" ));
HttpWebResponse^ HttpWResp = dynamic_cast<HttpWebResponse^>(HttpWReq->GetResponse());

// Insert code that uses the response object.
HttpWResp->Close();
HttpWebRequest HttpWReq =
(HttpWebRequest)WebRequest.Create("http://www.contoso.com");

HttpWebResponse HttpWResp = (HttpWebResponse)HttpWReq.GetResponse();
// Insert code that uses the response object.
HttpWResp.Close();
Dim HttpWReq As HttpWebRequest = _
   CType(WebRequest.Create("http://www.contoso.com"), HttpWebRequest)
       
Dim HttpWResp As HttpWebResponse = _
   CType(HttpWReq.GetResponse(), HttpWebResponse)
' Insert code that uses the response object.
HttpWResp.Close()

Remarks

This class contains support for HTTP-specific uses of the properties and methods of the WebResponse class. The HttpWebResponse class is used to build HTTP stand-alone client applications that send HTTP requests and receive HTTP responses.

Note

Do not confuse HttpWebResponse with the HttpResponse class that is used in ASP.NET applications and whose methods and properties are exposed through ASP.NET's intrinsic Response object.

You should never directly create an instance of the HttpWebResponse class. Instead, use the instance returned by a call to HttpWebRequest.GetResponse. You must call either the Stream.Close or the HttpWebResponse.Close method to close the response and release the connection for reuse. It is not necessary to call both Stream.Close and HttpWebResponse.Close, but doing so does not cause an error.

Common header information returned from the Internet resource is exposed as properties of the class. See the following table for a complete list. Other headers can be read from the Headers property as name/value pairs.

The following table shows the common HTTP headers that are available through properties of the HttpWebResponse class.

Header Property
Content-Encoding ContentEncoding
Content-Length ContentLength
Content-Type ContentType
Last-Modified LastModified
Server Server

The contents of the response from the Internet resource are returned as a Stream by calling the GetResponseStream method.

Constructors

HttpWebResponse()
Obsolete.
Obsolete.
Obsolete.
Obsolete.

Initializes a new instance of the HttpWebResponse class.

HttpWebResponse(SerializationInfo, StreamingContext)
Obsolete.
Obsolete.
Obsolete.

Initializes a new instance of the HttpWebResponse class from the specified SerializationInfo and StreamingContext instances.

Properties

CharacterSet

Gets the character set of the response.

ContentEncoding

Gets the method that is used to encode the body of the response.

ContentLength

Gets the length of the content returned by the request.

ContentType

Gets the content type of the response.

Cookies

Gets or sets the cookies that are associated with this response.

Headers

Gets the headers that are associated with this response from the server.

IsFromCache

Gets a Boolean value that indicates whether this response was obtained from the cache.

(Inherited from WebResponse)
IsMutuallyAuthenticated

Gets a Boolean value that indicates whether both client and server were authenticated.

IsMutuallyAuthenticated

Gets a Boolean value that indicates whether mutual authentication occurred.

(Inherited from WebResponse)
LastModified

Gets the last date and time that the contents of the response were modified.

Method

Gets the method that is used to return the response.

ProtocolVersion

Gets the version of the HTTP protocol that is used in the response.

ResponseUri

Gets the URI of the Internet resource that responded to the request.

Server

Gets the name of the server that sent the response.

StatusCode

Gets the status of the response.

StatusDescription

Gets the status description returned with the response.

SupportsHeaders

Gets a value that indicates whether headers are supported.

SupportsHeaders

Gets a value that indicates if headers are supported.

(Inherited from WebResponse)

Methods

Close()

Closes the response stream.

Close()

When overridden by a descendant class, closes the response stream.

(Inherited from WebResponse)
CreateObjRef(Type)

Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.

(Inherited from MarshalByRefObject)
Dispose()

Releases the unmanaged resources used by the WebResponse object.

(Inherited from WebResponse)
Dispose(Boolean)

Releases the unmanaged resources used by the HttpWebResponse, and optionally disposes of the managed resources.

Dispose(Boolean)

Releases the unmanaged resources used by the WebResponse object, and optionally disposes of the managed resources.

(Inherited from WebResponse)
Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode()

Returns a hash value for a HttpWebResponse instance.

GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetLifetimeService()
Obsolete.

Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
GetObjectData(SerializationInfo, StreamingContext)
Obsolete.
Obsolete.
Obsolete.

Populates a SerializationInfo with the data needed to serialize the target object.

GetObjectData(SerializationInfo, StreamingContext)
Obsolete.

Populates a SerializationInfo with the data that is needed to serialize the target object.

(Inherited from WebResponse)
GetResponseHeader(String)

Gets the contents of a header that was returned with the response.

GetResponseStream()

Gets the stream that is used to read the body of the response from the server.

GetType()

Gets the Type of the current instance.

(Inherited from Object)
InitializeLifetimeService()
Obsolete.

Obtains a lifetime service object to control the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
MemberwiseClone(Boolean)

Creates a shallow copy of the current MarshalByRefObject object.

(Inherited from MarshalByRefObject)
ToString()

Returns a string that represents the current object.

(Inherited from Object)

Explicit Interface Implementations

IDisposable.Dispose()

This API supports the product infrastructure and is not intended to be used directly from your code.

Releases all resources used by the HttpWebResponse.

IDisposable.Dispose()

When overridden in a derived class, releases all resources used by the WebResponse.

(Inherited from WebResponse)
ISerializable.GetObjectData(SerializationInfo, StreamingContext)
Obsolete.
Obsolete.
Obsolete.

Serializes this instance into the specified SerializationInfo object.

Applies to

See also