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 |
上次修改時間 | LastModified |
伺服器 | Server |
從因特網資源傳回回應的內容會藉由呼叫 GetResponseStream 方法傳回。Stream
Http |
已淘汰.
已淘汰.
已淘汰.
已淘汰.
初始化 HttpWebResponse 類別的新執行個體。 |
Http |
已淘汰.
已淘汰.
已淘汰.
從指定的 HttpWebResponse 和 SerializationInfo 執行個體,初始化 StreamingContext 類別的新執行個體。 |
Character |
取得回應的字元集。 |
Content |
取得用來將回應主體編碼的方法。 |
Content |
取得由要求傳回的內容長度。 |
Content |
取得回應的內容類型。 |
Cookies |
取得或設定與這個回應關聯的 Cookie。 |
Headers |
取得與伺服器的這個回應關聯的標頭。 |
Is |
取得 Boolean 值,指出這個回應是否從快取中取得。 (繼承來源 WebResponse) |
Is |
取得 Boolean 值,指出用戶端和伺服器是否都已驗證。 |
Is |
取得 Boolean 值,指出是否發生過相互驗證。 (繼承來源 WebResponse) |
Last |
取得最近修改回應內容的日期和時間。 |
Method |
取得用來傳回回應的方法。 |
Protocol |
取得回應使用的 HTTP 通訊協定版本。 |
Response |
取得回應要求之網際網路資源的 URI。 |
Server |
取得傳送回應的伺服器名稱。 |
Status |
取得回應的狀態。 |
Status |
取得隨回應傳回的狀態描述。 |
Supports |
取得指出是否支援標頭的值。 |
Supports |
取得指出是否支援標頭的值。 (繼承來源 WebResponse) |
IDisposable. |
此 API 支援此產品基礎結構,但無法直接用於程式碼之中。 釋放 HttpWebResponse 所使用的所有資源。 |
IDisposable. |
在衍生類別中覆寫時,釋放 WebResponse 使用的所有資源。 (繼承來源 WebResponse) |
ISerializable. |
已淘汰.
已淘汰.
已淘汰.
將這個執行個體序列化為指定的 SerializationInfo 物件。 |
產品 | 版本 |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 2.0, 2.1 |
UWP | 10.0 |