WebResponse WebResponse WebResponse WebResponse Class

定义

提供来自统一资源标识符 (URI) 的响应。Provides a response from a Uniform Resource Identifier (URI). 这是一个 abstract 类。This is an abstract class.

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

示例

下面的示例WebRequest从创建WebResponse实例。The following example creates a WebResponse instance from a WebRequest.

// Initialize the WebRequest.
WebRequest^ myRequest = WebRequest::Create( "http://www.contoso.com" );

// Return the response. 
WebResponse^ myResponse = myRequest->GetResponse();

// Code to use the WebResponse goes here.

// Close the response to free resources.
myResponse->Close();
// Initialize the WebRequest.
WebRequest myRequest = WebRequest.Create("http://www.contoso.com");

// Return the response. 
WebResponse myResponse = myRequest.GetResponse();

// Code to use the WebResponse goes here.

// Close the response to free resources.
myResponse.Close();

' Initialize the WebRequest.
Dim myRequest As WebRequest = WebRequest.Create("http://www.contoso.com")

' Return the response. 
Dim myResponse As WebResponse = myRequest.GetResponse()

' Code to use the WebResponse goes here.
' Close the response to free resources.
myResponse.Close()

注解

类是特定于协议的响应类派生自的基类。abstract WebResponseThe WebResponse class is the abstract base class from which protocol-specific response classes are derived. 应用程序可以使用WebResponse类的实例以协议不可知的方式参与请求和响应事务,而从派生的协议特定的WebResponse类可执行请求的详细信息。Applications can participate in request and response transactions in a protocol-agnostic manner using instances of the WebResponse class while protocol-specific classes derived from WebResponse carry out the details of the request.

客户端应用程序不WebResponse直接创建对象,而是通过对WebRequest实例GetResponse调用方法来创建。Client applications do not create WebResponse objects directly; they are created by calling the GetResponse method on a WebRequest instance.

继承者说明

当从WebResponse继承时,必须重写以下成员: ContentLengthContentTypeGetResponseStream()ResponseUriHeadersWhen you inherit from WebResponse, you must override the following members: ContentLength, ContentType, GetResponseStream(), ResponseUri, and Headers.

构造函数

WebResponse() WebResponse() WebResponse() WebResponse()

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

WebResponse(SerializationInfo, StreamingContext) WebResponse(SerializationInfo, StreamingContext) WebResponse(SerializationInfo, StreamingContext) WebResponse(SerializationInfo, StreamingContext)

WebResponseSerializationInfo 类的指定实例初始化 StreamingContext 类的新实例。Initializes a new instance of the WebResponse class from the specified instances of the SerializationInfo and StreamingContext classes.

属性

ContentLength ContentLength ContentLength ContentLength

当在子类中重写时,获取或设置接收的数据的内容长度。When overridden in a descendant class, gets or sets the content length of data being received.

ContentType ContentType ContentType ContentType

当在派生类中重写时,获取或设置接收的数据的内容类型。When overridden in a derived class, gets or sets the content type of the data being received.

Headers Headers Headers Headers

当在派生类中重写时,获取与此请求关联的标头名称/值对的集合。When overridden in a derived class, gets a collection of header name-value pairs associated with this request.

IsFromCache IsFromCache IsFromCache IsFromCache

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

IsMutuallyAuthenticated IsMutuallyAuthenticated IsMutuallyAuthenticated IsMutuallyAuthenticated

获取一个 Boolean 值,该值指示是否发生了相互身份验证。Gets a Boolean value that indicates whether mutual authentication occurred.

ResponseUri ResponseUri ResponseUri ResponseUri

当在派生类中重写时,获取实际响应此请求的 Internet 资源的 URI。When overridden in a derived class, gets the URI of the Internet resource that actually responded to the request.

SupportsHeaders SupportsHeaders SupportsHeaders SupportsHeaders

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

方法

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

当由子类重写时,将关闭响应流。When overridden by a descendant class, 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.

Dispose(Boolean) Dispose(Boolean) Dispose(Boolean) Dispose(Boolean)

释放由 WebResponse 对象使用的非托管资源,并可根据需要释放托管资源。Releases the unmanaged resources used by the WebResponse object, 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()

作为默认哈希函数。Serves as the default hash function.

(Inherited from Object)
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 that is needed to serialize the target object.

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

当在子类中重写时,从 Internet 资源返回数据流。When overridden in a descendant class, returns the data stream from the Internet resource.

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

当在派生类中被重写时,释放 WebResponse 使用的所有资源。When overridden in a derived class, releases all resources used by the WebResponse.

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

使用序列化 SerializationInfo 所需的数据来填充 WebResponse 实例。Populates a SerializationInfo instance with the data that is needed to serialize WebResponse.

适用于