static async Task Main(string[] args) { var _httpListener = new HttpListener(); _httpListener.Prefixes.Add("http://localhost:5000/"); _httpListener.Start(); while (true) { var listenerContext = await _httpListener.GetContextAsync(); var bytes = Encoding.UTF8.GetBytes("HHHHHHHHHHHHHHH"); await listenerContext.Response.OutputStream.WriteAsync(bytes, 0, bytes.Length); listenerContext.Response.Close(); } }
在Node 或者Python中,只用引入http 模块,就可以监听,相应http 请求了。.netCore 如上实现