HttpWebResponse HttpWebResponse HttpWebResponse HttpWebResponse Class

定义

提供 WebResponse 类的 HTTP 特定的实现。Provides an HTTP-specific implementation of the WebResponse class.

public ref class HttpWebResponse : System::Net::WebResponse, IDisposable, System::Runtime::Serialization::ISerializable
[System.Serializable]
public class HttpWebResponse : System.Net.WebResponse, IDisposable, System.Runtime.Serialization.ISerializable
type HttpWebResponse = class
    inherit WebResponse
    interface ISerializable
    interface IDisposable
Public Class HttpWebResponse
Inherits WebResponse
Implements IDisposable, ISerializable
继承
属性
实现

示例

下面的示例HttpWebResponse HttpWebRequest从返回。The following example returns an HttpWebResponse from an HttpWebRequest.

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();
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()

注解

此类包含对WebResponse类的属性和方法的 HTTP 特定的使用的支持。This class contains support for HTTP-specific uses of the properties and methods of the WebResponse class. HttpWebResponse类用于生成 http 独立客户端应用程序,这些应用程序可发送 http 请求和接收 http 响应。The HttpWebResponse class is used to build HTTP stand-alone client applications that send HTTP requests and receive HTTP responses.

备注

不要将在HttpWebResponse ASP.NET 应用HttpResponse程序中使用并且其方法和属性通过 ASP 公开的类混淆。NET 的内部Response对象。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.

切勿直接创建HttpWebResponse类的实例。You should never directly create an instance of the HttpWebResponse class. 请改用通过调用HttpWebRequest.GetResponse返回的实例。Instead, use the instance returned by a call to HttpWebRequest.GetResponse. 您必须调用Stream.Close HttpWebResponse.Close或方法来关闭响应并释放连接以便重复使用。You must call either the Stream.Close or the HttpWebResponse.Close method to close the response and release the connection for reuse. 不需要调用Stream.CloseHttpWebResponse.Close,但这样做不会导致错误。It is not necessary to call both Stream.Close and HttpWebResponse.Close, but doing so does not cause an error.

从 Internet 资源返回的公共标头信息作为类的属性公开。Common header information returned from the Internet resource is exposed as properties of the class. 有关完整列表,请参阅下表。See the following table for a complete list. 其他标头可以从Headers属性读取为名称/值对。Other headers can be read from the Headers property as name/value pairs.

下表显示可通过HttpWebResponse类的属性获得的常见 HTTP 标头。The following table shows the common HTTP headers that are available through properties of the HttpWebResponse class.

HeaderHeader PropertyProperty
内容编码Content-Encoding ContentEncoding
Content-lengthContent-Length ContentLength
Content-TypeContent-Type ContentType
上次修改时间Last-Modified LastModified
服务器Server Server

来自 Internet 资源的响应的内容Stream通过GetResponseStream调用方法返回为。The contents of the response from the Internet resource are returned as a Stream by calling the GetResponseStream method.

构造函数

HttpWebResponse() HttpWebResponse() HttpWebResponse() HttpWebResponse()

初始化 HttpWebResponse 类的新实例。Initializes a new instance of the HttpWebResponse class.

HttpWebResponse(SerializationInfo, StreamingContext) HttpWebResponse(SerializationInfo, StreamingContext) HttpWebResponse(SerializationInfo, StreamingContext) HttpWebResponse(SerializationInfo, StreamingContext)

根据指定的 SerializationInfoStreamingContext 实例初始化 HttpWebResponse 类的新实例。Initializes a new instance of the HttpWebResponse class from the specified SerializationInfo and StreamingContext instances.

属性

CharacterSet CharacterSet CharacterSet CharacterSet

获取响应的字符集。Gets the character set of the response.

ContentEncoding ContentEncoding ContentEncoding ContentEncoding

获取用于对响应体进行编码的方法。Gets the method that is used to encode the body of the response.

ContentLength ContentLength ContentLength ContentLength

获取请求返回的内容的长度。Gets the length of the content returned by the request.

ContentType ContentType ContentType ContentType

获取响应的内容类型。Gets the content type of the response.

Cookies Cookies Cookies Cookies

获取或设置与此响应关联的 Cookie。Gets or sets the cookies that are associated with this response.

Headers Headers Headers Headers

获取来自服务器的与此响应关联的标头。Gets the headers that are associated with this response from the server.

IsFromCache IsFromCache IsFromCache IsFromCache

获取一个 Boolean 值,该值指示此响应是否为从缓存中获取的。Gets a Boolean value that indicates whether this response was obtained from the cache.

(Inherited from WebResponse)
IsMutuallyAuthenticated IsMutuallyAuthenticated IsMutuallyAuthenticated IsMutuallyAuthenticated

获取一个 Boolean 值,该值指示客户端和服务器是否都已经过身份验证。Gets a Boolean value that indicates whether both client and server were authenticated.

LastModified LastModified LastModified LastModified

获取最后一次修改响应内容的日期和时间。Gets the last date and time that the contents of the response were modified.

Method Method Method Method

获取用于返回响应的方法。Gets the method that is used to return the response.

ProtocolVersion ProtocolVersion ProtocolVersion ProtocolVersion

获取响应中使用的 HTTP 协议的版本。Gets the version of the HTTP protocol that is used in the response.

ResponseUri ResponseUri ResponseUri ResponseUri

获取响应请求的 Internet 资源的 URI。Gets the URI of the Internet resource that responded to the request.

Server Server Server Server

获取发送响应的服务器的名称。Gets the name of the server that sent the response.

StatusCode StatusCode StatusCode StatusCode

获取响应的状态。Gets the status of the response.

StatusDescription StatusDescription StatusDescription StatusDescription

获取与响应一起返回的状态说明。Gets the status description returned with the response.

SupportsHeaders SupportsHeaders SupportsHeaders SupportsHeaders

获取指示标头是否受支持的值。Gets a value that indicates whether headers are supported.

方法

Close() Close() Close() Close()

关闭响应流。Closes the response stream.

CreateObjRef(Type) CreateObjRef(Type) CreateObjRef(Type) CreateObjRef(Type)

创建一个对象,该对象包含生成用于与远程对象进行通信的代理所需的全部相关信息。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() Dispose() Dispose() Dispose()

释放 WebResponse 对象使用的非托管资源。Releases the unmanaged resources used by the WebResponse object.

(Inherited from WebResponse)
Dispose(Boolean) Dispose(Boolean) Dispose(Boolean) Dispose(Boolean)

释放由 HttpWebResponse 使用的非托管资源,并可根据需要释放托管资源。Releases the unmanaged resources used by the HttpWebResponse, and optionally disposes of the managed resources.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

返回 HttpWebResponse 实例的哈希值。Returns a hash value for a HttpWebResponse instance.

GetLifetimeService() GetLifetimeService() GetLifetimeService() GetLifetimeService()

检索控制此实例的生存期策略的当前生存期服务对象。Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
GetObjectData(SerializationInfo, StreamingContext) GetObjectData(SerializationInfo, StreamingContext) GetObjectData(SerializationInfo, StreamingContext) GetObjectData(SerializationInfo, StreamingContext)

使用将目标对象序列化所需的数据填充 SerializationInfoPopulates a SerializationInfo with the data needed to serialize the target object.

GetResponseHeader(String) GetResponseHeader(String) GetResponseHeader(String) GetResponseHeader(String)

获取与响应一起返回的标头的内容。Gets the contents of a header that was returned with the response.

GetResponseStream() GetResponseStream() GetResponseStream() GetResponseStream()

获取流,该流用于读取来自服务器的响应的体。Gets the stream that is used to read the body of the response from the server.

GetType() GetType() GetType() GetType()

获取当前实例的 TypeGets the Type of the current instance.

(Inherited from Object)
InitializeLifetimeService() InitializeLifetimeService() InitializeLifetimeService() InitializeLifetimeService()

获取生存期服务对象来控制此实例的生存期策略。Obtains a lifetime service object to control the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(Inherited from Object)
MemberwiseClone(Boolean) MemberwiseClone(Boolean) MemberwiseClone(Boolean) MemberwiseClone(Boolean)

创建当前 MarshalByRefObject 对象的浅表副本。Creates a shallow copy of the current MarshalByRefObject object.

(Inherited from MarshalByRefObject)
ToString() ToString() ToString() ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(Inherited from Object)

显式界面实现

IDisposable.Dispose() IDisposable.Dispose() IDisposable.Dispose() IDisposable.Dispose()

释放由 HttpWebResponse 使用的所有资源。Releases all resources used by the HttpWebResponse.

ISerializable.GetObjectData(SerializationInfo, StreamingContext) ISerializable.GetObjectData(SerializationInfo, StreamingContext) ISerializable.GetObjectData(SerializationInfo, StreamingContext) ISerializable.GetObjectData(SerializationInfo, StreamingContext)

将此实例序列化到指定的 SerializationInfo 对象中。Serializes this instance into the specified SerializationInfo object.

适用于

另请参阅