HttpWebResponse 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
提供 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 從 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()
備註
這個類別包含對類別之屬性和方法 WebResponse 之 HTTP 特定用途的支援。 類別 HttpWebResponse 是用來建置 HTTP 獨立用戶端應用程式,以傳送 HTTP 要求和接收 HTTP 回應。
注意
請勿與 HttpResponse ASP.NET 應用程式中所使用的類別混淆 HttpWebResponse ,以及其方法和屬性會透過 ASP.NET 的內部 Response
物件公開。
您絕對不應該直接建立 類別的 HttpWebResponse 實例。 請改用 呼叫 所傳回的 HttpWebRequest.GetResponse 實例。 您必須呼叫 Stream.Close 或 HttpWebResponse.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) |
已過時。
已過時。
已過時。
已過時。
從指定的 HttpWebResponse 和 SerializationInfo 執行個體,初始化 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) |
方法
明確介面實作
IDisposable.Dispose() |
此 API 支援此產品基礎結構,但無法直接用於程式碼之中。 釋放 HttpWebResponse 所使用的所有資源。 |
IDisposable.Dispose() |
在衍生類別中覆寫時,釋放 WebResponse 使用的所有資源。 (繼承來源 WebResponse) |
ISerializable.GetObjectData(SerializationInfo, StreamingContext) |
已過時。
已過時。
已過時。
將這個執行個體序列化為指定的 SerializationInfo 物件。 |