HttpWebResponse 类

定义

提供 WebResponse 类的 HTTP 特定的实现。

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

示例

下面的示例返回一个 HttpWebResponse 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()

注解

此类包含对类的属性和方法的特定于 HTTP 的使用 WebResponse 的支持。 该 HttpWebResponse 类用于生成用于发送 HTTP 请求和接收 HTTP 响应的 HTTP 独立客户端应用程序。

备注

不要与 HttpResponse ASP.NET 应用程序中使用的类混淆HttpWebResponse,并且其方法和属性通过 ASP.NET 的内部Response对象公开。

不应直接创建类的 HttpWebResponse 实例。 请改用调用 HttpWebRequest.GetResponse返回的实例。 必须调用 Stream.CloseHttpWebResponse.Close 方法以关闭响应并释放连接以重复使用。 不需要同时 Stream.Close 调用, HttpWebResponse.Close但这样做不会导致错误。

从 Internet 资源返回的常见标头信息作为类的属性公开。 有关完整列表,请参阅下表。 可以从属性中读取 Headers 其他标头作为名称/值对。

下表显示了通过类的属性 HttpWebResponse 提供的常见 HTTP 标头。

标头 properties
Content-Encoding ContentEncoding
Content-Length ContentLength
Content-Type ContentType
Last-Modified LastModified
服务器 Server

通过调用GetResponseStream该方法,从 Internet 资源返回Stream响应的内容。

构造函数

HttpWebResponse()
已过时。
已过时。
已过时。
已过时。

初始化 HttpWebResponse 类的新实例。

HttpWebResponse(SerializationInfo, StreamingContext)
已过时。
已过时。
已过时。
已过时。

根据指定的 SerializationInfoStreamingContext 实例初始化 HttpWebResponse 类的新实例。

属性

CharacterSet

获取响应的字符集。

ContentEncoding

获取用于对响应体进行编码的方法。

ContentLength

获取请求返回的内容的长度。

ContentType

获取响应的内容类型。

Cookies

获取或设置与此响应关联的 Cookie。

Headers

获取来自服务器的与此响应关联的标头。

IsFromCache

获取一个 Boolean 值,该值指示此响应是否为从缓存中获取的。

(继承自 WebResponse)
IsMutuallyAuthenticated

获取一个 Boolean 值,该值指示客户端和服务器是否都已经过身份验证。

IsMutuallyAuthenticated

获取一个 Boolean 值,该值指示是否发生了相互身份验证。

(继承自 WebResponse)
LastModified

获取最后一次修改响应内容的日期和时间。

Method

获取用于返回响应的方法。

ProtocolVersion

获取响应中使用的 HTTP 协议的版本。

ResponseUri

获取响应请求的 Internet 资源的 URI。

Server

获取发送响应的服务器的名称。

StatusCode

获取响应的状态。

StatusDescription

获取与响应一起返回的状态说明。

SupportsHeaders

获取指示标头是否受支持的值。

SupportsHeaders

获取指示是否支持标题的值。

(继承自 WebResponse)

方法

Close()

关闭响应流。

Close()

当由子类重写时,将关闭响应流。

(继承自 WebResponse)
CreateObjRef(Type)

创建一个对象,该对象包含生成用于与远程对象进行通信的代理所需的全部相关信息。

(继承自 MarshalByRefObject)
Dispose()

释放 WebResponse 对象使用的非托管资源。

(继承自 WebResponse)
Dispose(Boolean)

释放由 HttpWebResponse 使用的非托管资源,并可根据需要释放托管资源。

Dispose(Boolean)

释放由 WebResponse 对象使用的非托管资源,并可根据需要释放托管资源。

(继承自 WebResponse)
Equals(Object)

确定指定对象是否等于当前对象。

(继承自 Object)
GetHashCode()

返回 HttpWebResponse 实例的哈希值。

GetHashCode()

作为默认哈希函数。

(继承自 Object)
GetLifetimeService()
已过时。

检索控制此实例的生存期策略的当前生存期服务对象。

(继承自 MarshalByRefObject)
GetObjectData(SerializationInfo, StreamingContext)
已过时。
已过时。
已过时。

使用将目标对象序列化所需的数据填充 SerializationInfo

GetObjectData(SerializationInfo, StreamingContext)
已过时。

使用序列化目标对象所需的数据填充 SerializationInfo

(继承自 WebResponse)
GetResponseHeader(String)

获取与响应一起返回的标头的内容。

GetResponseStream()

获取流,该流用于读取来自服务器的响应的体。

GetType()

获取当前实例的 Type

(继承自 Object)
InitializeLifetimeService()
已过时。

获取生存期服务对象来控制此实例的生存期策略。

(继承自 MarshalByRefObject)
MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
MemberwiseClone(Boolean)

创建当前 MarshalByRefObject 对象的浅表副本。

(继承自 MarshalByRefObject)
ToString()

返回表示当前对象的字符串。

(继承自 Object)

显式接口实现

IDisposable.Dispose()

此 API 支持产品基础结构,不能在代码中直接使用。

释放由 HttpWebResponse 使用的所有资源。

IDisposable.Dispose()

当在派生类中被重写时,释放 WebResponse 使用的所有资源。

(继承自 WebResponse)
ISerializable.GetObjectData(SerializationInfo, StreamingContext)
已过时。
已过时。
已过时。

将此实例序列化到指定的 SerializationInfo 对象中。

适用于

另请参阅