Skip to navigation
C# webserer
17.02.23
using System.Net; using System.Text; using var listener = new HttpListener(); listener.Prefixes.Add("http://localhost:8001/"); listener.Start(); Console.WriteLine("Listening on port 8001..."); while (true) { HttpListenerContext ctx = listener.GetContext(); HttpListenerRequest req = ctx.Request; string? ua = req.Headers.Get("User-Agent"); using HttpListenerResponse resp = ctx.Response; resp.Headers.Set("Content-Type", "text/plain"); string data = ua ?? "unknown"; byte[] buffer = Encoding.UTF8.GetBytes(data); resp.ContentLength64 = buffer.Length; using Stream ros = resp.OutputStream; ros.Write(buffer, 0, buffer.Length); }
https://www.zetcode.com/csharp/httplistener/
Reply
Anonymous
Information Epoch 1732453467
Small is beautiful.
Home
Notebook
Contact us