public class HttpWebResponse : WebResponse
Object
MarshalByRefObject
WebResponse
HttpWebResponseThis type implements IDisposable.
System
Networking
Provides an HTTP-specific implementation of the WebResponse class.
[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.
]
Header Set by Accept System.Net.HttpWebRequest.Accept Connection System.Net.HttpWebRequest.Connection System.Net.HttpWebRequest.KeepAlive
Content-Length System.Net.HttpWebRequest.ContentLength Content-Type System.Net.HttpWebRequest.ContentType Expect System.Net.HttpWebRequest.Expect Date Set to current date by the system. Host Set to current host by the system. if-Modified-since System.Net.HttpWebRequest.IfModifiedSince Range System.Net.HttpWebRequest.AddRange(System.Int32,System.Int32) Referer System.Net.HttpWebRequest.Referer Transfer-Encoding System.Net.HttpWebRequest.TransferEncoding System.Net.HttpWebRequest.SendChunked
User-Agent System.Net.HttpWebRequest.UserAgent
System.Net Namespace
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
public override void Close();
Closes the response stream.
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 might cause an application to run out of connections.
This method overrides System.Net.WebResponse.Close.
]
System.Net.HttpWebResponse Class, System.Net Namespace
protected virtual void Dispose(bool disposing);
Releases the unmanaged resources used by the current instance and optionally releases the managed resources.
- disposing
true
to release both managed and unmanaged resources;false
to release only unmanaged resources.
[Behaviors: When disposing istrue
, 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) can be called multiple times by other objects. . ]
System.Net.HttpWebResponse Class, System.Net Namespace
public override int GetHashCode();
Generates a hash code for the current instance.
A Int32 containing the hash code for the current instance.
Exception Type Condition ObjectDisposedException The current instance has been disposed.
The algorithm used to generate the hash code is unspecified.[Note: This method overrides System.Object.GetHashCode.]
System.Net.HttpWebResponse Class, System.Net Namespace
public string GetResponseHeader(string headerName);
Returns a specified header from the current response.
- headerName
- A String that specifies the header value to return.
A String containing the value of the specified header.
Exception Type Condition ObjectDisposedException The current instance has been disposed.
System.Net.HttpWebResponse Class, System.Net Namespace
public override Stream GetResponseStream();
Returns a Stream for reading the body of the response from the server.
A Stream containing the body of the response.
Exception Type Condition ObjectDisposedException The current instance has been disposed.
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 might cause an application to run out of connections.
This method overrides System.Net.WebResponse.GetResponseStream .
]
System.Net.HttpWebResponse Class, System.Net Namespace
public string CharacterSet { get; }
Gets the character set used for the current instance.
A String that represents the character set used for the current instance.
Exception Type Condition ObjectDisposedException The current instance has been disposed.
This property is read-only.[Note: For detailed information about character sets, see Section 3.4 of RFC 2616.]
System.Net.HttpWebResponse Class, System.Net Namespace
public string ContentEncoding { get; }
Gets the method used to encode the body of the response.
A String that describes the method used to encode the body of the response.
Exception Type Condition ObjectDisposedException The current instance has been disposed.
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.]
System.Net.HttpWebResponse Class, System.Net Namespace
public override long ContentLength { get; }
Gets the content length of the response data being received.
A Int64 containing the number of bytes returned from the Internet resource. This value does not include header information.
Exception Type Condition ObjectDisposedException The current instance has been disposed.
This property is read-only.The System.Net.HttpWebResponse.ContentLength property contains the value of the
Content-length
header returned with the response. If theContent-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 .]
System.Net.HttpWebResponse Class, System.Net Namespace
public override string ContentType { get; }
Gets the content type of the response.
A String that represents the content type of the response data.
Exception Type Condition ObjectDisposedException The current instance has been disposed.
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 .]
System.Net.HttpWebResponse Class, System.Net Namespace
public override WebHeaderCollection Headers { get; }
Gets the headers associated with the current response from the server.
A WebHeaderCollection containing the header information returned with the response.
Exception Type Condition ObjectDisposedException The current instance has been disposed.
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.
This property overrides System.Net.WebResponse.Headers.
Header Property Content-Encoding System.Net.HttpWebResponse.ContentEncoding Content-Length System.Net.HttpWebResponse.ContentLength Content-Type System.Net.HttpWebResponse.ContentType Last-Modified System.Net.HttpWebResponse.LastModified Server System.Net.HttpWebResponse.Server ]
System.Net.HttpWebResponse Class, System.Net Namespace
public DateTime LastModified { get; }
Gets the last date and time that the contents of the response were modified.
A DateTime value containing the date and time the contents of the response were modified.
Exception Type Condition ObjectDisposedException The current instance has been disposed.
This property is read-only.The System.Net.HttpWebResponse.LastModified property contains the value of the
Last-Modified
header received with the response.
System.Net.HttpWebResponse Class, System.Net Namespace
public string Method { get; }
Gets the method used to return the response.
A String that represents the HTTP method used to return the response.
Exception Type Condition ObjectDisposedException The current instance has been disposed.
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.
For detailed information regarding these methods, see sections 9.2 to 9.8 of RFC 2616.
Item Description GET Retrieves in entity-body form the information identified by the System.Net.HttpWebRequest.RequestUri property of the request associated with the current instance. HEAD Identical to GET except that the message-body is not returned in the response. POST Requests 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. PUT Requests that the enclosed entity be stored under the supplied Request-URI. DELETE Requests that the origin server delete the resource identified by the Request-URI. TRACE Invokes a remote, application-layer loopback of the request message. OPTIONS Requests 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.]
]
System.Net.HttpWebResponse Class, System.Net Namespace
public Version ProtocolVersion { get; }
Gets the version of the HTTP protocol used in the response.
A Version that contains the HTTP protocol version of the response.
Exception Type Condition ObjectDisposedException The current instance has been disposed.
This property is read-only.The System.Net.HttpWebResponse.ProtocolVersion property contains the HttpVersion number of the response sent by the Internet resource.
System.Net.HttpWebResponse Class, System.Net Namespace
public override Uri ResponseUri { get; }
Gets the Uri of the Internet resource that actually responded to the request.
A Uri representing the resource that actually responded to the request.
Exception Type Condition ObjectDisposedException The current instance has been disposed.
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 might 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 .
]
System.Net.HttpWebResponse Class, System.Net Namespace
public string Server { get; }
Gets the name of the server that sent the response.
A String containing the name of the server that sent the response.
Exception Type Condition ObjectDisposedException The current instance has been disposed.
This property is read-only.The System.Net.HttpWebResponse.Server property contains the value of the
Server
header returned with the response.
System.Net.HttpWebResponse Class, System.Net Namespace
public HttpStatusCode StatusCode { get; }
Gets the status of the response.
A HttpStatusCode value.
Exception Type Condition ObjectDisposedException The current instance has been disposed.
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.
System.Net.HttpWebResponse Class, System.Net Namespace
public string StatusDescription { get; }
Gets the status description returned with the response.
A String that describes the status of the response.
Exception Type Condition ObjectDisposedException The current instance has been disposed.
This property is read-only.
System.Net.HttpWebResponse Class, System.Net Namespace