HttpListenerRequest HttpListenerRequest HttpListenerRequest HttpListenerRequest Class


Describes an incoming HTTP request to an HttpListener object. This class cannot be inherited.

public ref class HttpListenerRequest sealed
public sealed class HttpListenerRequest
type HttpListenerRequest = class
Public NotInheritable Class HttpListenerRequest


The following code example demonstrates how to receive and respond to a HttpListenerRequest.

// This example requires the System and System.Net namespaces.
public static void SimpleListenerExample(string[] prefixes)
    if (!HttpListener.IsSupported)
        Console.WriteLine ("Windows XP SP2 or Server 2003 is required to use the HttpListener class.");
    // URI prefixes are required,
    // for example "".
    if (prefixes == null || prefixes.Length == 0)
      throw new ArgumentException("prefixes");
    // Create a listener.
    HttpListener listener = new HttpListener();
    // Add the prefixes.
    foreach (string s in prefixes)
    // Note: The GetContext method blocks while waiting for a request. 
    HttpListenerContext context = listener.GetContext();
    HttpListenerRequest request = context.Request;
    // Obtain a response object.
    HttpListenerResponse response = context.Response;
    // Construct a response.
    string responseString = "<HTML><BODY> Hello world!</BODY></HTML>";
    byte[] buffer = System.Text.Encoding.UTF8.GetBytes(responseString);
    // Get a response stream and write the response to it.
    response.ContentLength64 = buffer.Length;
    System.IO.Stream output = response.OutputStream;
    // You must close the output stream.


When a client makes a request to a Uniform Resource Identifier (URI) handled by an HttpListener object, the HttpListener provides a HttpListenerContext object that contains information about the sender, the request, and the response that is sent to the client. The HttpListenerContext.Request property returns the HttpListenerRequest object that describes the request.

The HttpListenerRequest object contains information about the request, such as the request HttpMethod string, UserAgent string, and request body data (see the InputStream property).

To reply to the request, you must get the associated response using the Response property.


AcceptTypes AcceptTypes AcceptTypes AcceptTypes

Gets the MIME types accepted by the client.

ClientCertificateError ClientCertificateError ClientCertificateError ClientCertificateError

Gets an error code that identifies a problem with the X509Certificate provided by the client.

ContentEncoding ContentEncoding ContentEncoding ContentEncoding

Gets the content encoding that can be used with data sent with the request

ContentLength64 ContentLength64 ContentLength64 ContentLength64

Gets the length of the body data included in the request.

ContentType ContentType ContentType ContentType

Gets the MIME type of the body data included in the request.

Cookies Cookies Cookies Cookies

Gets the cookies sent with the request.

HasEntityBody HasEntityBody HasEntityBody HasEntityBody

Gets a Boolean value that indicates whether the request has associated body data.

Headers Headers Headers Headers

Gets the collection of header name/value pairs sent in the request.

HttpMethod HttpMethod HttpMethod HttpMethod

Gets the HTTP method specified by the client.

InputStream InputStream InputStream InputStream

Gets a stream that contains the body data sent by the client.

IsAuthenticated IsAuthenticated IsAuthenticated IsAuthenticated

Gets a Boolean value that indicates whether the client sending this request is authenticated.

IsLocal IsLocal IsLocal IsLocal

Gets a Boolean value that indicates whether the request is sent from the local computer.

IsSecureConnection IsSecureConnection IsSecureConnection IsSecureConnection

Gets a Boolean value that indicates whether the TCP connection used to send the request is using the Secure Sockets Layer (SSL) protocol.

IsWebSocketRequest IsWebSocketRequest IsWebSocketRequest IsWebSocketRequest

Gets a Boolean value that indicates whether the TCP connection was a WebSocket request.

KeepAlive KeepAlive KeepAlive KeepAlive

Gets a Boolean value that indicates whether the client requests a persistent connection.

LocalEndPoint LocalEndPoint LocalEndPoint LocalEndPoint

Get the server IP address and port number to which the request is directed.

ProtocolVersion ProtocolVersion ProtocolVersion ProtocolVersion

Gets the HTTP version used by the requesting client.

QueryString QueryString QueryString QueryString

Gets the query string included in the request.

RawUrl RawUrl RawUrl RawUrl

Gets the URL information (without the host and port) requested by the client.

RemoteEndPoint RemoteEndPoint RemoteEndPoint RemoteEndPoint

Gets the client IP address and port number from which the request originated.

RequestTraceIdentifier RequestTraceIdentifier RequestTraceIdentifier RequestTraceIdentifier

Gets the request identifier of the incoming HTTP request.

ServiceName ServiceName ServiceName ServiceName

Gets the Service Provider Name (SPN) that the client sent on the request.

TransportContext TransportContext TransportContext TransportContext

Gets the TransportContext for the client request.

Url Url Url Url

Gets the Uri object requested by the client.

UrlReferrer UrlReferrer UrlReferrer UrlReferrer

Gets the Uniform Resource Identifier (URI) of the resource that referred the client to the server.

UserAgent UserAgent UserAgent UserAgent

Gets the user agent presented by the client.

UserHostAddress UserHostAddress UserHostAddress UserHostAddress

Gets the server IP address and port number to which the request is directed.

UserHostName UserHostName UserHostName UserHostName

Gets the DNS name and, if provided, the port number specified by the client.

UserLanguages UserLanguages UserLanguages UserLanguages

Gets the natural languages that are preferred for the response.


BeginGetClientCertificate(AsyncCallback, Object) BeginGetClientCertificate(AsyncCallback, Object) BeginGetClientCertificate(AsyncCallback, Object) BeginGetClientCertificate(AsyncCallback, Object)

Begins an asynchronous request for the client's X.509 v.3 certificate.

EndGetClientCertificate(IAsyncResult) EndGetClientCertificate(IAsyncResult) EndGetClientCertificate(IAsyncResult) EndGetClientCertificate(IAsyncResult)

Ends an asynchronous request for the client's X.509 v.3 certificate.

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

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetClientCertificate() GetClientCertificate() GetClientCertificate() GetClientCertificate()

Retrieves the client's X.509 v.3 certificate.

GetClientCertificateAsync() GetClientCertificateAsync() GetClientCertificateAsync() GetClientCertificateAsync()

Retrieves the client's X.509 v.3 certificate as an asynchronous operation.

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

Returns a string that represents the current object.

(Inherited from Object)

Applies to

See Also