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 override void handleGETRequest(HTTPProcessor p) { char[] delimiterChars = { '/' }; //make sure to throw the first one out //url is: /asd/qwe //*************first value will be empty************* String[] rest = p.http_url.Split(delimiterChars); if (rest[0] == rest[1]) { p.writeSuccess("application/json"); p.outputStream.WriteLine("[error:'Wrong REST API command!']" + p.http_url); return; } p.writeSuccess("application/json"); p.outputStream.WriteLine("rest length " + rest.Length); String eventsJson = ""; if (rest[1] == "all") { eventsJson = parseRESTallEvents(p); } else if (rest[1] == "help") { printHelp(p); return; } else if (rest[1] == "lastid") { try { eventsJson = parseRESTallEvents(p, Int32.Parse(rest[2])); } catch { p.outputStream.WriteLine("[error:'Wrong REST API command! URL: " + p.http_url + "']"); return; } } else if (rest[1] == "current") { p.outputStream.WriteLine("current" + p.http_url); return; try { //eventsJson = parseCurrent(p, Int32.Parse(rest[2])); } catch { p.outputStream.WriteLine("[error:'Wrong REST API command! URL: " + p.http_url + "']"); return; } } else if (parsePotentialSingleData(p, rest)) { p.outputStream.WriteLine("parsePotentialSingleData = true"); return; } else { p.outputStream.WriteLine("[error:'Wrong REST API command! URL: " + p.http_url + "']"); return; } p.outputStream.WriteLine("{\"events\":"); p.outputStream.WriteLine(eventsJson); p.outputStream.WriteLine("}"); }