using System; using System.Net; using System.IO; using System.Text; namespace HttpListenerTest { static class HttpListenerTest { public static void Main() { HttpListener listener = new HttpListener(); listener.Prefixes.Add("http://*:8088/"); listener.Start(); Console.WriteLine("Listening..."); for(int i = 0; i < 100; i++) { try { HttpListenerContext context = listener.GetContext(); // Create the response. HttpListenerResponse response = context.Response; response.StatusCode = 400; Console.WriteLine("handling request"); string responseString = "error"; byte[] buffer = Encoding.UTF8.GetBytes(responseString); response.ContentLength64 = buffer.Length; response.OutputStream.Write(buffer, 0, buffer.Length); if(response != null) response.Close(); } catch(Exception e) { Console.WriteLine(e.ToString()); } } listener.Close(); Console.WriteLine("Done Listening."); } } }