HttpListenerResponse HttpListenerResponse HttpListenerResponse HttpListenerResponse Class

定義

表示所處理的要求的回應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
繼承
HttpListenerResponseHttpListenerResponseHttpListenerResponseHttpListenerResponse
實作

備註

當用戶端會提出資源要求由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.

您可以藉由設定各種屬性,例如自訂的回應StatusCodeStatusDescription,和CookiesYou 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 ContentEncoding ContentEncoding ContentEncoding

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

ContentLength64 ContentLength64 ContentLength64 ContentLength64

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

ContentType ContentType ContentType ContentType

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

Cookies Cookies Cookies Cookies

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

Headers Headers Headers Headers

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

KeepAlive KeepAlive KeepAlive KeepAlive

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

OutputStream OutputStream OutputStream OutputStream

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

ProtocolVersion ProtocolVersion ProtocolVersion ProtocolVersion

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

RedirectLocation RedirectLocation RedirectLocation RedirectLocation

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

SendChunked SendChunked SendChunked SendChunked

取得或設定是否回應會使用區塊的傳輸編碼。Gets or sets whether the response uses chunked transfer encoding.

StatusCode StatusCode StatusCode StatusCode

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

StatusDescription StatusDescription StatusDescription StatusDescription

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

方法

Abort() Abort() Abort() Abort()

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

AddHeader(String, String) AddHeader(String, String) AddHeader(String, String) AddHeader(String, String)

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

AppendCookie(Cookie) AppendCookie(Cookie) AppendCookie(Cookie) AppendCookie(Cookie)

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

AppendHeader(String, String) AppendHeader(String, String) AppendHeader(String, String) AppendHeader(String, String)

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

Close() Close() Close() Close()

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

Close(Byte[], Boolean) Close(Byte[], Boolean) Close(Byte[], Boolean) Close(Byte[], Boolean)

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

CopyFrom(HttpListenerResponse) CopyFrom(HttpListenerResponse) CopyFrom(HttpListenerResponse) CopyFrom(HttpListenerResponse)

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

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

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

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

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

(Inherited from Object)
GetType() GetType() GetType() GetType()

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

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

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

(Inherited from Object)
Redirect(String) Redirect(String) Redirect(String) Redirect(String)

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

SetCookie(Cookie) SetCookie(Cookie) SetCookie(Cookie) SetCookie(Cookie)

新增或更新Cookie隨這個回應傳送的 cookie 集合中。Adds or updates a Cookie in the collection of cookies sent with this response.

ToString() ToString() ToString() ToString()

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

(Inherited from Object)

明確介面實作

IDisposable.Dispose() IDisposable.Dispose() IDisposable.Dispose() IDisposable.Dispose()

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

適用於

另請參閱