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); }
// THIS IS THE CORE CONCEPT I NEED TO LEARN /// Get animals public override void handleGETRequest(HttpProcessor p) { string heading; string message = ""; p.writeSuccess(); Console.WriteLine("request: {0}", p.http_url); p.outputStream.WriteLine("<html><head><title>Zoolandia</title></head><body>"); p.outputStream.WriteLine("Current Time: " + DateTime.Now.ToString()); string[] urlParams = p.http_url.Split('/'); string type = urlParams[1].ToString(); Console.WriteLine(type); switch (type) { case "animals": Console.WriteLine("Animal route"); if (urlParams.Length > 2) { Console.WriteLine("Getting a single animal"); AnimalHandler animals = new AnimalHandler(); message = animals.getAnimal(urlParams[2]); } else { Console.WriteLine("Getting all animals"); AnimalHandler animals = new AnimalHandler(); message = animals.getAllAnimals(); } break; case "habitats": break; case "employees": break; } p.outputStream.WriteLine(message); p.outputStream.WriteLine("</body></html>"); }