post.lua 1.2 KB

123456789101112131415161718192021222324252627282930313233
  1. return function (connection, req, args)
  2. connection:send("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\nCache-Control: private, no-store\r\n\r\n")
  3. connection:send('<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><title>Arguments</title></head>')
  4. connection:send('<body>')
  5. connection:send('<h1>Arguments</h1>')
  6. local form = [===[
  7. <form method="POST">
  8. First name:<br><input type="text" name="firstName"><br>
  9. Last name:<br><input type="text" name="lastName"><br>
  10. <input type="radio" name="sex" value="male" checked>Male<input type="radio" name="sex" value="female">Female<br>
  11. <input type="submit" value="Submit">
  12. </form>
  13. ]===]
  14. if req.method == "GET" then
  15. connection:send(form)
  16. elseif req.method == "POST" then
  17. local rd = req.getRequestData()
  18. -- connection:send(cjson.encode(rd))
  19. connection:send('<h2>Received the following values:</h2>')
  20. connection:send("<ul>\n")
  21. for name, value in pairs(rd) do
  22. connection:send('<li><b>' .. name .. ':</b> ' .. tostring(value) .. "<br></li>\n")
  23. end
  24. connection:send("</ul>\n")
  25. else
  26. connection:send("NOT IMPLEMENTED")
  27. end
  28. connection:send('</body></html>')
  29. end