![]() |
---|
The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience. |
Provides an HTTP-specific implementation of the WebResponse class.
Assembly: System (in System.dll)
[SerializableAttribute]
public class HttpWebResponse : WebResponse, ISerializable
[SerializableAttribute]
public ref class HttpWebResponse : WebResponse, ISerializable
[<SerializableAttribute>]
type HttpWebResponse =
class
inherit WebResponse
interface ISerializable
end
<SerializableAttribute>
Public Class HttpWebResponse
Inherits WebResponse
Implements ISerializable
Name | Description | |
---|---|---|
![]() | HttpWebResponse | Obsolete. Initializes a new instance of the HttpWebResponse class. |
![]() | HttpWebResponse | Obsolete. Initializes a new instance of the HttpWebResponse class from the specified SerializationInfo and StreamingContext instances. |
Name | Description | |
---|---|---|
![]() | Gets the character set of the response. | |
![]() | Gets the method that is used to encode the body of the response. | |
![]() | ||
![]() | ||
![]() | Gets or sets the cookies that are associated with this response. | |
![]() | ||
![]() | Gets a Boolean value that indicates whether this response was obtained from the cache.(Inherited from WebResponse.) | |
![]() | Gets a Boolean value that indicates whether both client and server were authenticated.(Overrides .) | |
![]() | Gets the last date and time that the contents of the response were modified. | |
![]() | Gets the method that is used to return the response. | |
![]() | Gets the version of the HTTP protocol that is used in the response. | |
![]() | ||
![]() | Gets the name of the server that sent the response. | |
![]() | Gets the status of the response. | |
![]() | Gets the status description returned with the response. | |
![]() |
Name | Description | |
---|---|---|
![]() | Close | Closes the response stream.(Overrides WebResponseClose.) |
![]() | 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.) |
![]() | Dispose | Releases the unmanaged resources used by the WebResponse object.(Inherited from WebResponse.) |
![]() | Dispose | Releases the unmanaged resources used by the HttpWebResponse, and optionally disposes of the managed resources.(Overrides WebResponseDispose.) |
![]() | Equals | Determines whether the specified object is equal to the current object.(Inherited from Object.) |
![]() | Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.(Inherited from Object.) |
![]() | GetHashCode | Serves as the default hash function. (Inherited from Object.) |
![]() | GetLifetimeService | Retrieves the current lifetime service object that controls the lifetime policy for this instance.(Inherited from MarshalByRefObject.) |
![]() | GetObjectData | This API supports the product infrastructure and is not intended to be used directly from your code. Populates a SerializationInfo with the data needed to serialize the target object.(Overrides WebResponseGetObjectData.) |
![]() | GetResponseHeader | Gets the contents of a header that was returned with the response. |
![]() | GetResponseStream | Gets the stream that is used to read the body of the response from the server.(Overrides WebResponseGetResponseStream.) |
![]() | GetType | |
![]() | InitializeLifetimeService | Obtains a lifetime service object to control the lifetime policy for this instance.(Inherited from MarshalByRefObject.) |
![]() | MemberwiseClone | |
![]() | MemberwiseClone | Creates a shallow copy of the current MarshalByRefObject object.(Inherited from MarshalByRefObject.) |
![]() | ToString | Returns a string that represents the current object.(Inherited from Object.) |
Name | Description | |
---|---|---|
![]() ![]() | ISerializableGetObjectData | This API supports the product infrastructure and is not intended to be used directly from your code. Serializes this instance into the specified SerializationInfo object. |
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.
![]() |
---|
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 HttpWebRequestGetResponse. You must call either the StreamClose or the HttpWebResponseClose method to close the response and release the connection for reuse. It is not necessary to call both StreamClose and HttpWebResponseClose, 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 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 | |
Content-Length | |
Content-Type | |
Last-Modified | |
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();
Dim HttpWReq As HttpWebRequest = _
CType(WebRequest.Create("http://www.contoso.com"), HttpWebRequest)
Dim HttpWResp As HttpWebResponse = _
CType(HttpWReq.GetResponse(), HttpWebResponse)
' Insert code that uses the response object.
HttpWResp.Close()
HttpWebRequest^ HttpWReq = dynamic_cast<HttpWebRequest^>(WebRequest::Create( "http://www.contoso.com" ));
HttpWebResponse^ HttpWResp = dynamic_cast<HttpWebResponse^>(HttpWReq->GetResponse());
// Insert code that uses the response object.
HttpWResp->Close();
Available since 8
.NET Framework
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
Any public static ( Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.