HttpListenerResponse 類別

定義

表示 HttpListener 物件所處理之要求的回應。Represents a response to a request being handled by an HttpListener object.

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 物件中提供給您的應用程式。When a client makes a request for a resource handled by an HttpListener object, the request and response are made available to your application in an HttpListenerContext object. 要求是以 HttpListenerRequest 物件表示,並可在 HttpListenerContext.Request 屬性中使用。The request is represented by an HttpListenerRequest object and is available in the HttpListenerContext.Request property. 回應是以 HttpListenerResponse 物件表示,並可在 HttpListenerContext.Response 屬性中使用。The response is represented by an HttpListenerResponse object and is available in the HttpListenerContext.Response property.

您可以藉由設定各種屬性(例如 StatusCodeStatusDescriptionCookies)來自訂回應。You can customize the response by setting various properties, such as StatusCode, StatusDescription, and Cookies. 使用 [HttpListenerResponse.OutputStream] 屬性,即可取得可寫入回應資料的 Stream 實例。Use the HttpListenerResponse.OutputStream property to obtain a Stream instance to which response data can be written. 最後,藉由呼叫 Close 方法,將回應資料傳送至用戶端。Finally, send the response data to the client by calling the Close method.

屬性

ContentEncoding

取得或設定這個回應之 EncodingOutputStreamGets or sets the Encoding for this response's OutputStream.

ContentLength64

取得或設定回應中所包含之主體資料的位元組數。Gets or sets the number of bytes in the body data included in the response.

ContentType

取得或設定傳回內容的 MIME 類型。Gets or sets the MIME type of the content returned.

Cookies

取得或設定隨回應所傳回之 Cookie 的集合。Gets or sets the collection of cookies returned with the response.

Headers

取得或設定伺服器所傳回之標頭名稱/值組的集合。Gets or sets the collection of header name/value pairs returned by the server.

KeepAlive

取得或設定值,指出伺服器是否要求持續性連線。Gets or sets a value indicating whether the server requests a persistent connection.

OutputStream

取得可寫入回應的 Stream 物件。Gets a Stream object to which a response can be written.

ProtocolVersion

取得或設定用於回應的 HTTP 版本。Gets or sets the HTTP version used for the response.

RedirectLocation

取得或設定在這個回應中 HTTP Location 標頭的值。Gets or sets the value of the HTTP Location header in this response.

SendChunked

取得或設定值,指出回應是否使用區塊傳輸編碼方式。Gets or sets whether the response uses chunked transfer encoding.

StatusCode

取得或設定傳回至用戶端的 HTTP 狀態碼。Gets or sets the HTTP status code to be returned to the client.

StatusDescription

取得或設定傳回至用戶端之 HTTP 狀態碼的文字描述。Gets or sets a text description of the HTTP status code returned to the client.

方法

Abort()

關閉與用戶端的連線,而不傳送回應。Closes the connection to the client without sending a response.

AddHeader(String, String)

將指定的標頭和值加入至這個回應的 HTTP 標頭。Adds the specified header and value to the HTTP headers for this response.

AppendCookie(Cookie)

針對這個回應,將指定的 Cookie 加入至 Cookie 的集合。Adds the specified Cookie to the collection of cookies for this response.

AppendHeader(String, String)

附加值至指定的 HTTP 標頭,隨這個回應傳送。Appends a value to the specified HTTP header to be sent with this response.

Close()

將回應傳送至用戶端,並釋放這個 HttpListenerResponse 執行個體所持有的資源。Sends the response to the client and releases the resources held by this HttpListenerResponse instance.

Close(Byte[], Boolean)

將指定的位元組陣列傳回至用戶端,並釋放這個 HttpListenerResponse 執行個體所持有的資源。Returns the specified byte array to the client and releases the resources held by this HttpListenerResponse instance.

CopyFrom(HttpListenerResponse)

從指定的 HttpListenerResponse 複製屬性至這個回應。Copies properties from the specified HttpListenerResponse to this response.

Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(繼承來源 Object)
GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

(繼承來源 Object)
Redirect(String)

將回應設定為重新導向用戶端至指定的 URL。Configures the response to redirect the client to the specified URL.

SetCookie(Cookie)

隨這個回應傳送的 Cookie 集合中,加入或更新 CookieAdds or updates a Cookie in the collection of cookies sent with this response.

ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(繼承來源 Object)

明確介面實作

IDisposable.Dispose()

釋放 HttpListenerResponse 所使用的所有資源。Releases all resources used by the HttpListenerResponse.

適用於

另請參閱