Table of Contents

Class HttpWebResponse

Namespace
System.Net
Assembly
System.Net.Http.dll

Handles retrieval of HTTP Response headers, and handles data reads.

public class HttpWebResponse : WebResponse, IDisposable
Inheritance
HttpWebResponse
Implements
Inherited Members
Extension Methods

Remarks

This class should never be created directly, but rather should be created by the HttpWebRequest.GetResponse() method.

Properties

ContentEncoding

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

public string ContentEncoding { get; }

Property Value

string

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

Remarks

This property contains the value of the Content-Encoding header returned with the response; that is, the encoding used for the response.

ContentLength

Gets the length of the content returned by the request.

public override long ContentLength { get; }

Property Value

long

The number of bytes returned by the request. Content length does not include header information.

Remarks

This property contains the value of the Content-Length header that is returned with the response. If the Content-Length header is not set in the response, this property is set to -1.

ContentType

Gets the content type of the response.

public override string ContentType { get; }

Property Value

string

A string that contains the content type of the response.

Remarks

This property contains the value of the Content-Type header returned with the response.

Headers

Retrieves a response header object.

public override WebHeaderCollection Headers { get; }

Property Value

WebHeaderCollection

A WebHeaderCollection that contains the header information returned with the response.

LastModified

Gets the value of the Last-Modified header, which indicates the last time the document was modified.

public DateTime LastModified { get; }

Property Value

DateTime

A DateTime that contains the date and time that the contents of the response were modified.

Method

Gets the method that is used to return the response.

public string Method { get; }

Property Value

string

A string that contains the HTTP method that is used to return the response.

ProtocolVersion

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

public Version ProtocolVersion { get; }

Property Value

Version

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

ResponseUri

Gets the final Response URI, that includes any changes that may have transpired from the orginal Request.

public override Uri ResponseUri { get; }

Property Value

Uri

A Uri that contains the URI of the Internet resource that responded to the request.

Server

Gets the name of the server that sent the response.

public string Server { get; }

Property Value

string

A string that contains the name of the server that sent the response.

StatusCode

Gets the status of the HTTP response, as a number.

public HttpStatusCode StatusCode { get; }

Property Value

HttpStatusCode

One of the HttpStatusCode values.

Remarks

For status code values, see HttpStatusCode.

StatusDescription

Gets the status description returned with the response.

public string StatusDescription { get; }

Property Value

string

A string that describes the status of the response.

Methods

Close()

Closes the response stream.

public override void Close()

Remarks

The Close() method closes the response stream and releases the connection to the resource for reuse by other requests. You should not access any properties of the HttpWebResponse object after the call to the Close() method. You must call either the Close() or the Close() method to close the stream and release the connection for reuse. It is not necessary to call both Close() and Close(), but doing so does not cause an error. Failure to close the stream can cause your application to run out of connections.

Dispose(bool)

Closes a response stream, if present.

protected override void Dispose(bool disposing)

Parameters

disposing bool

Not used.

GetResponseHeader(string)

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

public string GetResponseHeader(string headerName)

Parameters

headerName string

HTTP header to search for matching header on.

Returns

string

The matched entry, if found.

GetResponseStream()

Gets the stream used for reading the body of the response from the server.

public override Stream GetResponseStream()

Returns

Stream

A network stream to read body of the message.