Language

HttpListener Constructor

Definition

Initializes a new instance of the HttpListener class. The HttpListener type is not recommended for new development; for more information, see the Remarks section.

public:
 HttpListener();
public HttpListener();
Public Sub New ()

Exceptions

This class cannot be used on the current operating system. Windows Server 2003 or Windows XP SP2 is required to use instances of this class.

Examples

The following code example demonstrates using the HttpListener constructor to create a new HttpListener object. For the complete example, see the HttpListener class topic.

// Set up a listener.
HttpListener listener = new HttpListener();
foreach (string s in prefixes)
{
    listener.Prefixes.Add(s);
}
listener.Start();
For Each s As String In prefixes
    listener.Prefixes.Add(s)
Next

listener.Start()

Remarks

Caution

We recommend that you don't use the HttpListener class for new development. HttpListener receives only limited servicing, and its behavior and protocol support vary by platform because each platform uses a different underlying implementation. For example, on Windows it's built on HTTP.sys, while on Linux and macOS it uses a managed implementation that doesn't support HTTPS and offers a narrower set of features. Use ASP.NET Core instead, which provides a fully supported, cross-platform, and higher-performance HTTP server.

Before using the instance returned by this constructor, you must invoke its Start method.

Notes to Callers

Note: This member outputs trace information when you enable network tracing in your application. For more information, see Network Tracing in the .NET Framework.

Applies to