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
繼承
屬性
實作

範例

下列範例會傳回HttpWebResponseHttpWebRequestThe 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()

備註

這個類別包含支援的屬性和方法會使用的 HTTP 特定WebResponse類別。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.

注意

請勿混淆HttpWebResponseHttpResponse類別,用在 ASP.NET 應用程式,並透過 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.GetResponseInstead, use the instance returned by a call to HttpWebRequest.GetResponse. 您必須呼叫Stream.CloseHttpWebResponse.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.

傳回自網際網路資源的常見標頭資訊會公開為類別的屬性。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.

下表顯示一般的 HTTP 標頭,可透過內容HttpWebResponse類別。The following table shows the common HTTP headers that are available through properties of the HttpWebResponse class.

頁首Header 屬性Property
Content-EncodingContent-Encoding ContentEncoding
Content-LengthContent-Length ContentLength
Content-TypeContent-Type ContentType
Last-ModifiedLast-Modified LastModified
伺服器Server Server

從網際網路資源回應的內容會以傳回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)

從指定的 HttpWebResponseSerializationInfo 執行個體,初始化 StreamingContext 類別的新執行個體。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

取得回應要求之網際網路資源的 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)

建立包含所有相關資訊的物件,這些資訊是產生用來與遠端物件通訊的所需 Proxy。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 物件使用的 Unmanaged 資源。Releases the unmanaged resources used by the WebResponse object.

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

釋放 HttpWebResponse 所使用的 Unmanaged 資源,並選擇性處置 Managed 資源。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()

擷取控制這個執行個體存留期 (Lifetime) 原則的目前存留期服務物件。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 的淺層複本 (Shallow Copy)。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.

適用於

另請參閱