// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.Collections.Specialized; using System.IO; using System.Net; namespace E { public class WebServer { public static void Main(string[] args) { HttpListener srv = new HttpListener(); srv.Prefixes.Add("http://localhost:800/"); srv.Start(); while(true) { HttpListenerContext ctx = srv.GetContext(); HttpListenerRequest req = ctx.Request; HttpListenerResponse resp = ctx.Response; Console.WriteLine(req.Url.AbsolutePath); foreach(String k in req.Headers.AllKeys) { Console.WriteLine(k + " = " + req.Headers[k]); } foreach(String k in req.QueryString.AllKeys) { Console.WriteLine(k + " = " + req.QueryString[k]); } StreamWriter sw = new StreamWriter(resp.OutputStream); sw.WriteLine("Det virker"); sw.Close(); } //srv.Stop(); //srv.Close(); } } }