我认为HttpListener可能会做你想要的.
编辑:(添加代码示例以防万一)
这里有一些代码来展示如何使用它(使用异步方法).
HttpListener _server = new HttpListener();
// add server prefix (this is just one sample)
_server.Prefixes.Add("http://*:8080");
// start listening
_server.Start();
// kick off the listening thread
_Server.BeginGetContext(new AsyncCallback(ContextCallback), null);
Run Code Online (Sandbox Code Playgroud)
然后在 ContextCallback(IAsyncResult result)
// get the next request
HttpListenerContext context = _server.EndGetContext(result);
// write this method to inspect the context object
// and do whatever logic you need
HandleListenerContext(context);
// is the server is still running, wait for the next request
if (_Server.IsListening)
{
_server.BeginGetContext(new AsyncCallback(ServerThread), null);
}
Run Code Online (Sandbox Code Playgroud)
看一下HttpListenerContext,了解您可以使用的内容,但主要内容可能是Request属性.