HttpListenerResponse HttpListenerResponse HttpListenerResponse HttpListenerResponse Class


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


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. The request is represented by an HttpListenerRequest object and is available in the HttpListenerContext.Request property. The response is represented by an HttpListenerResponse object and is available in the HttpListenerContext.Response property.

You can customize the response by setting various properties, such as StatusCode, StatusDescription, and Cookies. Use the HttpListenerResponse.OutputStream property to obtain a Stream instance to which response data can be written. Finally, send the response data to the client by calling the Close method.


ContentEncoding ContentEncoding ContentEncoding ContentEncoding

Gets 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

Gets or sets the MIME type of the content returned.

Cookies Cookies Cookies Cookies

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

Gets a Stream object to which a response can be written.

ProtocolVersion ProtocolVersion ProtocolVersion ProtocolVersion

Gets or sets the HTTP version used for the response.

RedirectLocation RedirectLocation RedirectLocation RedirectLocation

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

Gets or sets the HTTP status code to be returned to the client.

StatusDescription StatusDescription StatusDescription StatusDescription

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)

Adds the specified header and value to the HTTP headers for this response.

AppendCookie(Cookie) AppendCookie(Cookie) AppendCookie(Cookie) AppendCookie(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)

Appends a value to the specified HTTP header to be sent with this response.

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

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)

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)

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()

Gets the Type of the current instance.

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

Creates a shallow copy of the current Object.

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

Configures the response to redirect the client to the specified URL.

SetCookie(Cookie) SetCookie(Cookie) SetCookie(Cookie) SetCookie(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)

Explicit Interface Implementations

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

Releases all resources used by the HttpListenerResponse.

Applies to

See also