HttpListenerResponse 類別

定義

表示 HttpListener 物件所處理之要求的回應。

public ref class HttpListenerResponse sealed : IDisposable
public sealed class HttpListenerResponse : IDisposable
type HttpListenerResponse = class
    interface IDisposable
Public NotInheritable Class HttpListenerResponse
Implements IDisposable
繼承
HttpListenerResponse
實作

備註

當用戶端對物件所 HttpListener 處理的資源提出要求時,會將要求和回應提供給物件中的 HttpListenerContext 應用程式使用。 要求是以 HttpListenerRequest 物件表示,而且可在 屬性中使用 HttpListenerContext.Request 。 回應是以 HttpListenerResponse 物件表示, HttpListenerContext.Response 而且可在 屬性中使用。

您可以藉由設定各種屬性來自訂回應,例如 StatusCodeStatusDescriptionCookiesHttpListenerResponse.OutputStream使用 屬性來取得 Stream 可寫入回應資料的實例。 最後,呼叫 Close 方法,將回應資料傳送至用戶端。

屬性

ContentEncoding

取得或設定這個回應之 EncodingOutputStream

ContentLength64

取得或設定回應中所包含之主體資料的位元組數。

ContentType

取得或設定傳回內容的 MIME 類型。

Cookies

取得或設定隨回應所傳回之 Cookie 的集合。

Headers

取得或設定伺服器所傳回之標頭名稱/值組的集合。

KeepAlive

取得或設定值,指出伺服器是否要求持續性連線。

OutputStream

取得可寫入回應的 Stream 物件。

ProtocolVersion

取得或設定用於回應的 HTTP 版本。

RedirectLocation

取得或設定在這個回應中 HTTP Location 標頭的值。

SendChunked

取得或設定值,指出回應是否使用區塊傳輸編碼方式。

StatusCode

取得或設定傳回至用戶端的 HTTP 狀態碼。

StatusDescription

取得或設定傳回至用戶端之 HTTP 狀態碼的文字描述。

方法

Abort()

關閉與用戶端的連線,而不傳送回應。

AddHeader(String, String)

將指定的標頭和值加入至這個回應的 HTTP 標頭。

AppendCookie(Cookie)

針對這個回應,將指定的 Cookie 加入至 Cookie 的集合。

AppendHeader(String, String)

附加值至指定的 HTTP 標頭,隨這個回應傳送。

Close()

將回應傳送至用戶端,並釋放這個 HttpListenerResponse 執行個體所持有的資源。

Close(Byte[], Boolean)

將指定的位元組陣列傳回至用戶端,並釋放這個 HttpListenerResponse 執行個體所持有的資源。

CopyFrom(HttpListenerResponse)

從指定的 HttpListenerResponse 複製屬性至這個回應。

Equals(Object)

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

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
Redirect(String)

將回應設定為重新導向用戶端至指定的 URL。

SetCookie(Cookie)

隨這個回應傳送的 Cookie 集合中,加入或更新 Cookie

ToString()

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

(繼承來源 Object)

明確介面實作

IDisposable.Dispose()

釋放 HttpListenerResponse 所使用的所有資源。

適用於

另請參閱