System.Net.HttpWebResponse Class

public class HttpWebResponse : WebResponse

Base Types

Object
  MarshalByRefObject
    WebResponse
      HttpWebResponse

This type implements IDisposable.

Assembly

System

Library

Networking

Summary

Provides an HTTP-specific implementation of the WebResponse class.

Description

[Note: The HttpWebResponse class contains support for the properties and methods included in WebResponse with additional elements that enable the user to interact directly with the Hypertext Transfer Protocol (HTTP).

Expected usage is that instances of this class are not created directly but are obtained by calling System.Net.HttpWebRequest.GetResponse . To obtain the response from the Internet resource as a Stream , call the System.Net.HttpWebResponse.GetResponseStream method.

Certain HTTP headers are protected such that the user cannot set them directly in the header collection. Instead, these headers can be set via the properties of the HttpWebRequest class or are set by the system. The following table details these protected headers.

HeaderSet by
AcceptSystem.Net.HttpWebRequest.Accept
ConnectionSystem.Net.HttpWebRequest.Connection

System.Net.HttpWebRequest.KeepAlive

Content-LengthSystem.Net.HttpWebRequest.ContentLength
Content-TypeSystem.Net.HttpWebRequest.ContentType
ExpectSystem.Net.HttpWebRequest.Expect
DateSet to current date by the system.
HostSet to current host by the system.
if-Modified-sinceSystem.Net.HttpWebRequest.IfModifiedSince
RangeSystem.Net.HttpWebRequest.AddRange(System.Int32,System.Int32)
RefererSystem.Net.HttpWebRequest.Referer
Transfer-EncodingSystem.Net.HttpWebRequest.TransferEncoding

System.Net.HttpWebRequest.SendChunked

User-AgentSystem.Net.HttpWebRequest.UserAgent
]

See Also

System.Net Namespace

Members

HttpWebResponse Methods

HttpWebResponse.Close Method
HttpWebResponse.Dispose Method
HttpWebResponse.GetHashCode Method
HttpWebResponse.GetResponseHeader Method
HttpWebResponse.GetResponseStream Method

HttpWebResponse Properties

HttpWebResponse.CharacterSet Property
HttpWebResponse.ContentEncoding Property
HttpWebResponse.ContentLength Property
HttpWebResponse.ContentType Property
HttpWebResponse.Headers Property
HttpWebResponse.LastModified Property
HttpWebResponse.Method Property
HttpWebResponse.ProtocolVersion Property
HttpWebResponse.ResponseUri Property
HttpWebResponse.Server Property
HttpWebResponse.StatusCode Property
HttpWebResponse.StatusDescription Property


HttpWebResponse.Close Method

public override void Close();

Summary

Closes the response stream.

Description

The System.Net.HttpWebResponse.Close method closes the response stream and releases the connection to the Internet resource for reuse by other requests.

[Note: Call either the System.IO.Stream.Close or System.Net.HttpWebResponse.Close method to close the stream and release the connection for reuse. It is not necessary to call both System.IO.Stream.Close and System.Net.HttpWebResponse.Close , but doing so does not cause an error. Failure to close the stream may cause an application to run out of connections.

This method overrides System.Net.WebResponse.Close.

]

See Also

System.Net.HttpWebResponse Class, System.Net Namespace

HttpWebResponse.Dispose Method

protected virtual void Dispose(bool disposing);

Summary

Releases the unmanaged resources used by the current instance and optionally releases the managed resources.

Parameters

disposing
true to release both managed and unmanaged resources; false to release only unmanaged resources.

Description

[Behaviors: When disposing is true , this method releases all resources held by any managed objects that the current instance references.]

[Overrides: When overriding System.Net.HttpWebResponse.Dispose(System.Boolean)(Boolean), be careful not to reference objects that have been previously disposed in an earlier call to System.Net.HttpWebResponse.Dispose(System.Boolean) as System.Net.HttpWebResponse.Dispose(System.Boolean) may be called multiple times by other objects. . ]

See Also

System.Net.HttpWebResponse Class, System.Net Namespace

HttpWebResponse.GetHashCode Method

public override int GetHashCode();

Summary

Generates a hash code for the current instance.

Return Value

A Int32 containing the hash code for the current instance.

Exceptions

Exception TypeCondition
ObjectDisposedExceptionThe current instance has been disposed.

Description

The algorithm used to generate the hash code is unspecified.

[Note: This method overrides System.Object.GetHashCode.]

See Also

System.Net.HttpWebResponse Class, System.Net Namespace

HttpWebResponse.GetResponseHeader Method

public string GetResponseHeader(string headerName);

Summary

Returns a specified header from the current response.

Parameters

headerName
A String that specifies the header value to return.

Return Value

A String containing the value of the specified header.

Exceptions

Exception TypeCondition
ObjectDisposedExceptionThe current instance has been disposed.

See Also

System.Net.HttpWebResponse Class, System.Net Namespace

HttpWebResponse.GetResponseStream Method

public override Stream GetResponseStream();

Summary

Returns a Stream for reading the body of the response from the server.

Return Value

A Stream containing the body of the response.

Exceptions

Exception TypeCondition
ObjectDisposedExceptionThe current instance has been disposed.

Description

The System.Net.HttpWebResponse.GetResponseStream method returns the data stream from the requested Internet resource.

[Note: Call either the System.IO.Stream.Close or System.Net.HttpWebResponse.Close method to close the stream and release the connection for reuse. It is not necessary to call both System.IO.Stream.Close and System.Net.HttpWebResponse.Close , but doing so does not cause an error. Failure to close the stream may cause an application to run out of connections.

This method overrides System.Net.WebResponse.GetResponseStream .

]

See Also

System.Net.HttpWebResponse Class, System.Net Namespace

HttpWebResponse.CharacterSet Property

public string CharacterSet { get; }

Summary

Gets the character set used for the current instance.

Property Value

A String that represents the character set used for the current instance.

Exceptions

Exception TypeCondition
ObjectDisposedExceptionThe current instance has been disposed.

Description

This property is read-only.

[Note: For detailed information about character sets, see Section 3.4 of RFC 2616.]

See Also

System.Net.HttpWebResponse Class, System.Net Namespace

HttpWebResponse.ContentEncoding Property

public string ContentEncoding { get; }

Summary

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

Property Value

A String that describes the method used to encode the body of the response.

Exceptions

Exception TypeCondition
ObjectDisposedExceptionThe current instance has been disposed.

Description

This property is read-only.

The System.Net.HttpWebResponse.ContentEncoding property contains the value of the Content-Encoding header returned with the response.

[Note: For detailed information about content encoding, see Section 3.5 of RFC 2616.]

See Also

System.Net.HttpWebResponse Class, System.Net Namespace

HttpWebResponse.ContentLength Property

public override long ContentLength { get; }

Summary

Gets the content length of the response data being received.

Property Value

A Int64 containing the number of bytes returned from the Internet resource. This value does not include header information.

Exceptions

Exception TypeCondition
ObjectDisposedExceptionThe current instance has been disposed.

Description

This property is read-only.

The System.Net.HttpWebResponse.ContentLength property contains the value of the Content-length header returned with the response. If the Content-length header is not set in the response, System.Net.HttpWebResponse.ContentLength is set to the value -1.

[Note: This property overrides System.Net.WebResponse.ContentLength .]

See Also

System.Net.HttpWebResponse Class, System.Net Namespace

HttpWebResponse.ContentType Property

public override string ContentType { get; }

Summary

Gets the content type of the response.

Property Value

A String that represents the content type of the response data.

Exceptions

Exception TypeCondition
ObjectDisposedExceptionThe current instance has been disposed.

Description

This property is read-only.

The System.Net.HttpWebResponse.ContentType property contains the value of the Content-Type header returned with the response.

[Note: This property overrides System.Net.WebResponse.ContentType .]

See Also

System.Net.HttpWebResponse Class, System.Net Namespace

HttpWebResponse.Headers Property

public override WebHeaderCollection Headers { get; }

Summary

Gets the headers associated with the current response from the server.

Property Value

A WebHeaderCollection containing the header information returned with the response.

Exceptions

Exception TypeCondition
ObjectDisposedExceptionThe current instance has been disposed.

Description

This property is read-only.

[Note: The System.Net.HttpWebResponse.Headers property is a collection of name/value pairs containing the HTTP header values returned with the response. The following table lists common headers and the properties that store their values.

HeaderProperty
Content-EncodingSystem.Net.HttpWebResponse.ContentEncoding
Content-LengthSystem.Net.HttpWebResponse.ContentLength
Content-TypeSystem.Net.HttpWebResponse.ContentType
Last-ModifiedSystem.Net.HttpWebResponse.LastModified
ServerSystem.Net.HttpWebResponse.Server
This property overrides System.Net.WebResponse.Headers.

]

See Also

System.Net.HttpWebResponse Class, System.Net Namespace

HttpWebResponse.LastModified Property

public DateTime LastModified { get; }

Summary

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

Property Value

A DateTime value containing the date and time the contents of the response were modified.

Exceptions

Exception TypeCondition
ObjectDisposedExceptionThe current instance has been disposed.

Description

This property is read-only.

The System.Net.HttpWebResponse.LastModified property contains the value of the Last-Modified header received with the response.

See Also

System.Net.HttpWebResponse Class, System.Net Namespace

HttpWebResponse.Method Property

public string Method { get; }

Summary

Gets the method used to return the response.

Property Value

A String that represents the HTTP method used to return the response.

Exceptions

Exception TypeCondition
ObjectDisposedExceptionThe current instance has been disposed.

Description

This property is read-only.

[Note: The System.Net.HttpWebRequest.Method property can be set to any of the HTTP 1.1 protocol methods: GET, HEAD, POST, PUT, DELETE, TRACE, or OPTIONS. The following table describes these methods.

ItemDescription
GETRetrieves in entity-body form the information identified by the System.Net.HttpWebRequest.RequestUri property of the request associated with the current instance.
HEADIdentical to GET except that the message-body is not returned in the response.
POSTRequests that the origin server accept the entity enclosed in the request as a new subordinate of the resource identified the Request-URI in the Request-Line.
PUTRequests that the enclosed entity be stored under the supplied Request-URI.
DELETERequests that the origin server delete the resource identified by the Request-URI.
TRACEInvokes a remote, application-layer loopback of the request message.
OPTIONSRequests information about the communication options available on the request/response chain identified by the Request-URI. [Note: This allows the client to determine the options and/or requirements associated with a resource, or the capabilities of a server, without implying a resource action or initiating a resource retrieval.]

For detailed information regarding these methods, see sections 9.2 to 9.8 of RFC 2616.

]

See Also

System.Net.HttpWebResponse Class, System.Net Namespace

HttpWebResponse.ProtocolVersion Property

public Version ProtocolVersion { get; }

Summary

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

Property Value

A Version that contains the HTTP protocol version of the response.

Exceptions

Exception TypeCondition
ObjectDisposedExceptionThe current instance has been disposed.

Description

This property is read-only.

The System.Net.HttpWebResponse.ProtocolVersion property contains the HttpVersion number of the response sent by the Internet resource.

See Also

System.Net.HttpWebResponse Class, System.Net Namespace

HttpWebResponse.ResponseUri Property

public override Uri ResponseUri { get; }

Summary

Gets the Uri of the Internet resource that actually responded to the request.

Property Value

A Uri representing the resource that actually responded to the request.

Exceptions

Exception TypeCondition
ObjectDisposedExceptionThe current instance has been disposed.

Description

This property is read-only.

[Note: The System.Net.HttpWebResponse.ResponseUri property contains the URI of the Internet resource that actually responded to the request. This URI may not be the same as the originally requested URI if the request was redirected by the original server.

This method overrides System.Net.WebResponse.ResponseUri .

]

See Also

System.Net.HttpWebResponse Class, System.Net Namespace

HttpWebResponse.Server Property

public string Server { get; }

Summary

Gets the name of the server that sent the response.

Property Value

A String containing the name of the server that sent the response.

Exceptions

Exception TypeCondition
ObjectDisposedExceptionThe current instance has been disposed.

Description

This property is read-only.

The System.Net.HttpWebResponse.Server property contains the value of the Server header returned with the response.

See Also

System.Net.HttpWebResponse Class, System.Net Namespace

HttpWebResponse.StatusCode Property

public HttpStatusCode StatusCode { get; }

Summary

Gets the status of the response.

Property Value

A HttpStatusCode value.

Exceptions

Exception TypeCondition
ObjectDisposedExceptionThe current instance has been disposed.

Description

This property is read-only.

The System.Net.HttpWebResponse.StatusCode value indicates the status of the HTTP response. The expected values are defined in the HttpStatusCode enumeration.

See Also

System.Net.HttpWebResponse Class, System.Net Namespace

HttpWebResponse.StatusDescription Property

public string StatusDescription { get; }

Summary

Gets the status description returned with the response.

Property Value

A String that describes the status of the response.

Exceptions

Exception TypeCondition
ObjectDisposedExceptionThe current instance has been disposed.

Description

This property is read-only.

See Also

System.Net.HttpWebResponse Class, System.Net Namespace