Condividi tramite


HttpWebResponse Class

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

Provides an HTTP-specific implementation of the WebResponse class.

Inheritance Hierarchy

System..::.Object
  System.Net..::.WebResponse
    System.Net..::.HttpWebResponse

Namespace:  System.Net
Assembly:  System.Net (in System.Net.dll)

Syntax

Public Class HttpWebResponse _
    Inherits WebResponse _
    Implements IDisposable
public class HttpWebResponse : WebResponse, 
    IDisposable

The HttpWebResponse type exposes the following members.

Constructors

  Name Description
HttpWebResponse Initializes a new instance of the WebResponse class.

Top

Properties

  Name Description
ContentLength Gets the length of the content returned by the request. (Overrides WebResponse..::.ContentLength.)
ContentType Gets the content type of the response. (Overrides WebResponse..::.ContentType.)
Cookies Gets the cookies used to persist state information for the HTTP response.
Headers Gets the headers that are associated with this response from the server. (Overrides WebResponse..::.Headers.)
Method Gets the method that is used to return the response.
ResponseUri Gets the URI of the Internet resource that responded to the request. (Overrides WebResponse..::.ResponseUri.)
StatusCode Gets the status of the response.
StatusDescription Gets the status description returned with the response.
SupportsHeaders Gets a value that indicates if headers are supported. (Overrides WebResponse..::.SupportsHeaders.)

Top

Methods

  Name Description
Close Closes the response stream. (Overrides WebResponse..::.Close()()().)
Dispose()()() Releases the resources used by the current instance of the WebResponse class. (Inherited from WebResponse.)
Dispose(Boolean) Releases the unmanaged resources used by the HttpWebResponse and optionally releases the managed resources. (Overrides WebResponse..::.Dispose(Boolean).)
Equals(Object) 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 the Object is reclaimed by garbage collection. (Inherited from Object.)
GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
GetResponseStream Gets the stream that is used to read the body of the response from the server. (Overrides WebResponse..::.GetResponseStream()()().)
GetType Gets the Type of the current instance. (Inherited from Object.)
MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
ToString Returns a string that represents the current object. (Inherited from Object.)

Top

Explicit Interface Implementations

  Name Description
IDisposable..::.Dispose Infrastructure. Releases all resources used by the HttpWebResponse.

Top

Remarks

This class contains support for HTTP-specific uses of the properties and methods of the WebResponse class. The HttpWebResponse class is used to build applications that send HTTP requests and receive HTTP responses.

You should never directly create an instance of the HttpWebResponse class. Instead, use the instance returned by a call to HttpWebRequest..::.BeginGetResponse.

You must call either the Close or Stream..::.Close method to close the response and release the connection for reuse. It is not necessary to call both the Close and the Stream..::.Close method, 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. Headers for the request can be read from the Headers property as name/value pairs.

The following table shows the values that are available through properties of the HttpWebResponse class.

Header

Property

HTTP method

Method

Status code

StatusCode

Status description

StatusDescription

The contents of the response from the Internet resource are returned as a Stream by calling the GetResponseStream method.

Capabilities

If you use this API in your app, you must specify the following capabilities in the app manifest. Otherwise, your app might not work correctly or it might exit unexpectedly.

ID_CAP_NETWORKING

Windows Phone 8, Windows Phone OS 7.1

For more info, see App capabilities and hardware requirements for Windows Phone 8.

Version Information

Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Platforms

Windows Phone

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

See Also

Reference

System.Net Namespace

WebResponse