共用方式為


HttpWebResponse 類別

定義

提供該類別的 HTTP 專用實作 WebResponse

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

範例

以下範例從 中回傳 an HttpWebResponseHttpWebRequest

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 。 此 HttpWebResponse 類別用於建構 HTTP 獨立客戶端應用程式,這些應用程式能發送 HTTP 請求並接收 HTTP 回應。

備註

不要與 HttpResponse ASP.NET 應用中使用的類別混HttpWebResponse淆,且其方法與屬性透過 ASP 揭露。NET的內在Response物件。

你絕對不應該直接建立該 HttpWebResponse 類別的實例。 取而代之的是,使用呼叫回 HttpWebRequest.GetResponse傳的實例。 你必須呼叫 或 Stream.Close 方法 HttpWebResponse.Close 來關閉回應並釋放連線以便重複使用。 不必同時呼叫 Stream.CloseHttpWebResponse.Close,但這樣做不會造成錯誤。

從網際網路資源回傳的常見標頭資訊會被揭露為類別的屬性。 完整列表請參見下表。 其他標頭可從 Headers 屬性中讀取為名稱/值對。

下表顯示了透過類別屬性 HttpWebResponse 提供的常見 HTTP 標頭。

Header 房產
內容編碼 ContentEncoding
內容長度 ContentLength
內容類型 ContentType
Last-Modified(最後修改時間) LastModified
伺服器 Server

來自網際網路資源的回應內容會透過呼叫該GetResponseStream方法返回為 aStream

建構函式

名稱 Description
HttpWebResponse()
已淘汰.
已淘汰.
已淘汰.
已淘汰.

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

HttpWebResponse(SerializationInfo, StreamingContext)
已淘汰.
已淘汰.
已淘汰.

從指定的 SerializationInfoStreamingContext 實例中初始化該類別的新實例HttpWebResponse

屬性

名稱 Description
CharacterSet

取得回應的字元集。

ContentEncoding

取得用來編碼回應內容的方法。

ContentLength

會取得請求回傳的內容長度。

ContentType

能理解回應的內容類型。

Cookies

取得或設定與此回應相關的 Cookie。

Headers

從伺服器取得與此回應相關的標頭。

IsFromCache

會得到 Boolean 一個值,表示該回應是否來自快取。

(繼承來源 WebResponse)
IsMutuallyAuthenticated

會得到 Boolean 一個值,表示用戶端和伺服器是否都被認證。

LastModified

取得回覆內容被修改的最後日期和時間。

Method

取得回傳回應的方法。

ProtocolVersion

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

ResponseUri

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

Server

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

StatusCode

會收到回覆的狀態。

StatusDescription

回覆後會回傳狀態描述。

SupportsHeaders

會獲得一個值,表示標頭是否被支援。

方法

名稱 Description
Close()

關閉回應流。

CreateObjRef(Type)

建立一個物件,包含產生代理伺服器所需的所有相關資訊,用於與遠端物件通訊。

(繼承來源 MarshalByRefObject)
Dispose()

釋放物件所使用的 WebResponse 未管理資源。

(繼承來源 WebResponse)
Dispose(Boolean)

釋放 所使用的 HttpWebResponse未管理資源,並可選擇性地處置這些受管理資源。

Equals(Object)

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

(繼承來源 Object)
GetHashCode()

回傳一個實例的 HttpWebResponse 雜湊值。

GetHashCode()

做為預設哈希函式。

(繼承來源 Object)
GetLifetimeService()
已淘汰.

取得目前控制此實例生命週期政策的終身服務物件。

(繼承來源 MarshalByRefObject)
GetObjectData(SerializationInfo, StreamingContext)
已淘汰.
已淘汰.
已淘汰.

將序列化目標物件所需的資料填充 a SerializationInfo

GetResponseHeader(String)

會取得一個隨回應回傳的標頭內容。

GetResponseStream()

取得用來讀取伺服器回應內容的串流。

GetType()

取得目前實例的 Type

(繼承來源 Object)
InitializeLifetimeService()
已淘汰.

取得一個終身服務物件以控制此實例的終身政策。

(繼承來源 MarshalByRefObject)
MemberwiseClone()

建立目前 Object的淺層複本。

(繼承來源 Object)
MemberwiseClone(Boolean)

建立一個 MarshalByRefObject 目前物件的淺層複製品。

(繼承來源 MarshalByRefObject)
ToString()

傳回表示目前 物件的字串。

(繼承來源 Object)

明確介面實作

名稱 Description
IDisposable.Dispose()

此 API 支援此產品基礎結構,但無法直接用於程式碼之中。

釋放所有由 HttpWebResponse.

IDisposable.Dispose()

當在衍生類別中覆寫時,會釋放所有由 WebResponse.

(繼承來源 WebResponse)
ISerializable.GetObjectData(SerializationInfo, StreamingContext)
已淘汰.
已淘汰.
已淘汰.

將此實例序列化為指定的 SerializationInfo 物件。

適用於

另請參閱