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

範例

下列範例會 HttpWebResponseHttpWebRequest 傳回 。

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 特定用途的支援。 類別 HttpWebResponse 是用來建置 HTTP 獨立用戶端應用程式,以傳送 HTTP 要求和接收 HTTP 回應。

注意

請勿與 HttpResponse ASP.NET 應用程式中所使用的類別混淆 HttpWebResponse ,以及其方法和屬性會透過 ASP.NET 的內部 Response 物件公開。

您絕對不應該直接建立 類別的 HttpWebResponse 實例。 請改用 呼叫 所傳回的 HttpWebRequest.GetResponse 實例。 您必須呼叫 Stream.CloseHttpWebResponse.Close 方法,以關閉回應並釋放連接以供重複使用。 不需要同時 Stream.Close 呼叫 和 HttpWebResponse.Close ,但這樣做不會造成錯誤。

從網際網路資源傳回的通用標頭資訊會公開為 類別的屬性。 如需完整清單,請參閱下表。 其他標頭可以從 屬性讀取 Headers 為名稱/值組。

下表顯示可透過 類別屬性取得的 HttpWebResponse 通用 HTTP 標頭。

標頭 屬性
Content-Encoding ContentEncoding
Content-Length ContentLength
Content-Type ContentType
Last-Modified LastModified
伺服器 Server

從網際網路資源傳迴響應的內容會藉由呼叫 GetResponseStream 方法傳回。 Stream

建構函式

HttpWebResponse()
已過時。
已過時。
已過時。
已過時。

初始化 HttpWebResponse 類別的新執行個體。

HttpWebResponse(SerializationInfo, StreamingContext)
已過時。
已過時。
已過時。
已過時。

從指定的 HttpWebResponseSerializationInfo 執行個體,初始化 StreamingContext 類別的新執行個體。

屬性

CharacterSet

取得回應的字元集。

ContentEncoding

取得用來將回應主體編碼的方法。

ContentLength

取得由要求傳回的內容長度。

ContentType

取得回應的內容類型。

Cookies

取得或設定與這個回應關聯的 Cookie。

Headers

取得與伺服器的這個回應關聯的標頭。

IsFromCache

取得 Boolean 值,指出這個回應是否從快取中取得。

(繼承來源 WebResponse)
IsMutuallyAuthenticated

取得 Boolean 值,指出用戶端和伺服器是否都已驗證。

IsMutuallyAuthenticated

取得 Boolean 值,指出是否發生過相互驗證。

(繼承來源 WebResponse)
LastModified

取得最近修改回應內容的日期和時間。

Method

取得用來傳回回應的方法。

ProtocolVersion

取得回應使用的 HTTP 通訊協定版本。

ResponseUri

取得回應要求之網際網路資源的 URI。

Server

取得傳送回應的伺服器名稱。

StatusCode

取得回應的狀態。

StatusDescription

取得隨回應傳回的狀態描述。

SupportsHeaders

取得指出是否支援標頭的值。

SupportsHeaders

取得指出是否支援標頭的值。

(繼承來源 WebResponse)

方法

Close()

關閉回應資料流。

Close()

當由子系類別覆寫時,關閉回應資料流。

(繼承來源 WebResponse)
CreateObjRef(Type)

建立包含所有相關資訊的物件,這些資訊是產生用來與遠端物件通訊的所需 Proxy。

(繼承來源 MarshalByRefObject)
Dispose()

釋放由 WebResponse 物件使用的 Unmanaged 資源。

(繼承來源 WebResponse)
Dispose(Boolean)

釋放 HttpWebResponse 所使用的 Unmanaged 資源,並選擇性處置 Managed 資源。

Dispose(Boolean)

釋放 WebResponse 物件所使用的 Unmanaged 資源,並選擇性處置 Managed 資源。

(繼承來源 WebResponse)
Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetHashCode()

傳回 HttpWebResponse 執行個體的雜湊值。

GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetLifetimeService()
已過時。

擷取控制這個執行個體存留期 (Lifetime) 原則的目前存留期服務物件。

(繼承來源 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 物件。

適用於

另請參閱