This topic has not yet been rated - Rate this topic

HttpWebResponse Class

Provides an HTTP-specific implementation of the WebResponse class.

System.Object
  System.MarshalByRefObject
    System.Net.WebResponse
      System.Net.HttpWebResponse

Namespace:  System.Net
Assembly:  System (in System.dll)
[SerializableAttribute]
public class HttpWebResponse : WebResponse, 
	ISerializable

The HttpWebResponse type exposes the following members.

  Name Description
Protected method HttpWebResponse Obsolete. Initializes a new instance of the HttpWebResponse class from the specified SerializationInfo and StreamingContext instances.
Top
  Name Description
Public property CharacterSet Gets the character set of the response.
Public property ContentEncoding Gets the method that is used to encode the body of the response.
Public property ContentLength Gets the length of the content returned by the request. (Overrides WebResponse.ContentLength.)
Public property ContentType Gets the content type of the response. (Overrides WebResponse.ContentType.)
Public property Supported by Portable Class Library Cookies Gets or sets the cookies that are associated with this response.
Public property Headers Gets the headers that are associated with this response from the server. (Overrides WebResponse.Headers.)
Public property IsFromCache Gets a Boolean value that indicates whether this response was obtained from the cache. (Inherited from WebResponse.)
Public property IsMutuallyAuthenticated Gets a Boolean value that indicates whether both client and server were authenticated. (Overrides WebResponse.IsMutuallyAuthenticated.)
Public property LastModified Gets the last date and time that the contents of the response were modified.
Public property Supported by Portable Class Library Method Gets the method that is used to return the response.
Public property ProtocolVersion Gets the version of the HTTP protocol that is used in the response.
Public property ResponseUri Gets the URI of the Internet resource that responded to the request. (Overrides WebResponse.ResponseUri.)
Public property Server Gets the name of the server that sent the response.
Public property Supported by Portable Class Library StatusCode Gets the status of the response.
Public property Supported by Portable Class Library StatusDescription Gets the status description returned with the response.
Public property Supported by Portable Class Library SupportsHeaders (Inherited from WebResponse.)
Top
  Name Description
Public method Close Closes the response stream. (Overrides WebResponse.Close().)
Public method CreateObjRef Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object. (Inherited from MarshalByRefObject.)
Public method Supported by Portable Class Library Dispose() (Inherited from WebResponse.)
Protected method Supported by Portable Class Library Dispose(Boolean) (Inherited from WebResponse.)
Public method Supported by Portable Class Library Equals(Object) Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected method Supported by Portable Class Library Finalize Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public method Supported by Portable Class Library GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
Public method GetLifetimeService Retrieves the current lifetime service object that controls the lifetime policy for this instance. (Inherited from MarshalByRefObject.)
Protected method GetObjectData Infrastructure. Populates a SerializationInfo with the data needed to serialize the target object. (Overrides WebResponse.GetObjectData(SerializationInfo, StreamingContext).)
Public method GetResponseHeader Gets the contents of a header that was returned with the response.
Public method GetResponseStream Gets the stream that is used to read the body of the response from the server. (Overrides WebResponse.GetResponseStream().)
Public method Supported by Portable Class Library GetType Gets the Type of the current instance. (Inherited from Object.)
Public method InitializeLifetimeService Obtains a lifetime service object to control the lifetime policy for this instance. (Inherited from MarshalByRefObject.)
Protected method Supported by Portable Class Library MemberwiseClone() Creates a shallow copy of the current Object. (Inherited from Object.)
Protected method MemberwiseClone(Boolean) Creates a shallow copy of the current MarshalByRefObject object. (Inherited from MarshalByRefObject.)
Public method Supported by Portable Class Library ToString Returns a string that represents the current object. (Inherited from Object.)
Top
  Name Description
Explicit interface implemetation Private method IDisposable.Dispose Infrastructure. When overridden in a derived class, releases all resources used by the WebResponse. (Inherited from WebResponse.)
Explicit interface implemetation Private method ISerializable.GetObjectData Infrastructure. Serializes this instance into the specified SerializationInfo object.
Top

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 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.

The following example returns an HttpWebResponse from an HttpWebRequest.


HttpWebRequest HttpWReq = 
(HttpWebRequest)WebRequest.Create("http://www.contoso.com");

HttpWebResponse HttpWResp = (HttpWebResponse)HttpWReq.GetResponse();
// Insert code that uses the response object.
HttpWResp.Close();


.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ