System.Net.WebResponse Class

Inheritance hierarchy:

System.Object > System.MarshalByRefObject > System.Net.WebResponse

public abstract class WebResponse : IDisposable, ISerializable

Overview

Represents a response from a network resource.

The WebResponse class is an abstract base class that provides a response from an Internet resource to an application. When you make a request to an Internet resource using a class like HttpWebRequest or FtpWebRequest, the server returns a response. The WebResponse class provides access to the data returned by the server.

In most cases, you will not work directly with the WebResponse class. Instead, you will work with a derived class that is specific to the protocol you are using. For example, if you are making an HTTP request, you will work with the HttpWebResponse class. If you are making an FTP request, you will work with the FtpWebResponse class.

The GetResponseStream() method returns a stream that contains the response data from the server. You can read from this stream to get the data returned by the server.

Properties

Name Description
ContentEncoding Gets the content encoding of the response stream.
ContentLength Gets the length of the content returned by the server.
ContentType Gets the content type of the response.
Headers Gets the headers received from the server.
IsMutuallyAuthenticated Gets a value indicating whether the server certificate is implicitly or explicitly trusted.
ResponseUri Gets the URI of the server that sent the response.

Methods

Name Description
Close() Closes the response stream.
Dispose() Releases the resources used by the WebResponse object.
GetResponseStream() Returns a stream that allows you to read the HTTP body of the response.

Remarks

When you use a class derived from WebResponse (such as HttpWebResponse) to get a response from a server, you should always close the response. If you don't close the response, you can consume system resources.

The WebResponse object is not thread-safe. If you need to access a WebResponse object from multiple threads, you should synchronize your access.

See Also

System.Net Namespace | HttpWebResponse | WebRequest