我在OpenWRT上的uhttpd上使用Lua,嘗試編寫我自己的門戶來捕獲自定義嵌入作業的表單數據。如何從OpenWRT上讀Lua的POST/uhttpd
我不需要路由器和LUCI的東西來完成這項工作,儘管我已經通過現有的Lua腳本拖動了沒有任何突破。
我很困惑uhttpd如何將POST數據放入Lua腳本中。這是如何發生的?什麼是我在最終的Lua腳本中訪問的POST和GET變量? (在PHP中,這是$ _POST,$ _GET或php://輸入,ruby on rails是請求對象,python有cgi.FieldStorage()或request.POST ...它是什麼在Lua上/ uhttpd?)
這是一個簡單的示例腳本。
前端/index.html:
<!DOCTYPE html>
<html>
<body>
<form action="/cgi/luascripts/processform.lua" method="post">
<input type="email" name="email" placeholder="[email protected]" />
<input type="submit" value="submit" />
</form>
</body>
</html>
後端/cgi-bin/luascripts/processform.lua:
-- some magic happens to bring POST data into email variable (how does this happen?)
-- email = '[email protected]'
output = [[
Hello {email}
]]
output = output:gsub("{email}", email)
print(output)
瀏覽器輸出:
Hello [email protected]
任何瞭解進入這個過程將是驚人的,謝謝!