public override void handleGETRequest(HttpProcessor p) { string relPath = Uri.UnescapeDataString(p.http_url); string path = Path.Combine(_htDocsRoot, relPath.TrimStart(new[] { '/', '\\' })); if (File.Exists(path)) { using (Stream fs = File.Open(path, FileMode.Open)) { p.writeSuccess(GetMimeType(Path.GetExtension(path))); fs.CopyTo(p.outputStream.BaseStream); p.outputStream.BaseStream.Flush(); } } else { p.writeFailure(); } }
public override void handlePOSTRequest(HttpProcessor p, StreamReader inputData) { Console.WriteLine("POST request: {0}", p.http_url); string data = inputData.ReadToEnd(); p.writeSuccess(); p.outputStream.WriteLine("<html><body><h1>test server</h1>"); p.outputStream.WriteLine("<a href=/test>return</a><p>"); p.outputStream.WriteLine("postbody: <pre>{0}</pre>", data); }
public abstract void handlePOSTRequest(HttpProcessor p, StreamReader inputData);
public void listen() { try { IPAddress ipAddress = IPAddress.Parse("127.0.0.1"); listener = new TcpListener(ipAddress, port); listener.Start(); while (is_active) { TcpClient s = listener.AcceptTcpClient(); HttpProcessor processor = new HttpProcessor(s, this); Thread thread = new Thread(processor.process); thread.Start(); Thread.Sleep(1); } } catch (Exception ex) { // Just swallow everything... Logger.Error("Exception occurred in Micro HttpServer: " + ex.ToString()); } }
public abstract void handleGETRequest(HttpProcessor p);