通过


HttpWebResponse 类

定义

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

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
继承
属性
实现

示例

以下示例从一个 HttpWebResponseHttpWebRequest.

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 的使用的支持。 该 HttpWebResponse 类用于生成 HTTP 独立客户端应用程序,用于发送 HTTP 请求和接收 HTTP 响应。

注释

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

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

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

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

Header 财产
内容编码 ContentEncoding
内容长度 ContentLength
内容类型 ContentType
最后修改 LastModified
服务器 Server

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

构造函数

名称 说明
HttpWebResponse()
已过时.
已过时.
已过时.
已过时.

初始化 HttpWebResponse 类的新实例。

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

从指定SerializationInfo实例和StreamingContext实例初始化类的新实例HttpWebResponse

属性

名称 说明
CharacterSet

获取响应的字符集。

ContentEncoding

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

ContentLength

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

ContentType

获取响应的内容类型。

Cookies

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

Headers

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

IsFromCache

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

(继承自 WebResponse)
IsMutuallyAuthenticated

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

LastModified

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

Method

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

ProtocolVersion

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

ResponseUri

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

Server

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

StatusCode

获取响应的状态。

StatusDescription

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

SupportsHeaders

获取一个值,该值指示是否支持标头。

方法

名称 说明
Close()

关闭响应流。

CreateObjRef(Type)

创建一个对象,其中包含生成用于与远程对象通信的代理所需的所有相关信息。

(继承自 MarshalByRefObject)
Dispose()

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

(继承自 WebResponse)
Dispose(Boolean)

释放由托管资源使用 HttpWebResponse的非托管资源,并选择性地释放托管资源。

Equals(Object)

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

(继承自 Object)
GetHashCode()

返回实例的 HttpWebResponse 哈希值。

GetHashCode()

用作默认哈希函数。

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

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

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

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

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 对象。

适用于

另请参阅