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 的浅表副本。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()

返回一个表示当前对象的 string。Returns a string that represents the current object.

(继承自 Object)

显式接口实现

IDisposable.Dispose()

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

适用于

另请参阅