post.lua 1.1 KB

1234567891011121314151617181920212223242526272829
  1. return function (connection, req, args)
  2. dofile("httpserver-header.lc")(connection, 200, 'html')
  3. connection:send([===[
  4. <!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><title>Arguments by POST</title></head><body><h1>Arguments by POST</h1>
  5. ]===])
  6. if req.method == "GET" then
  7. connection:send([===[
  8. <form method="POST">
  9. First name:<br><input type="text" name="firstName"><br>
  10. Last name:<br><input type="text" name="lastName"><br>
  11. <input type="radio" name="sex" value="male" checked>Male<input type="radio" name="sex" value="female">Female<br>
  12. <input type="submit" name="submit" value="Submit">
  13. </form>
  14. ]===])
  15. elseif req.method == "POST" then
  16. local rd = req.getRequestData()
  17. connection:send('<h2>Received the following values:</h2>')
  18. connection:send("<ul>\n")
  19. for name, value in pairs(rd) do
  20. connection:send('<li><b>' .. name .. ':</b> ' .. tostring(value) .. "<br></li>\n")
  21. end
  22. connection:send("</ul>\n")
  23. else
  24. connection:send("ERROR WTF req.method is ", req.method)
  25. end
  26. connection:send('</body></html>')
  27. end