1
我正在學習與lua(wsapi和uWSGI)的網絡開發。 我試圖創建一個請求對象(https://keplerproject.github.io/wsapi/libraries.html)以查看它的外觀(以及如何使用它)。因此,我建立了一個示例代碼:如何創建請求對象?
require "wsapi.cgi"
function run(wsapi_env)
local headers = { ["Content-type"] = "text/html" }
local function hello_text()
local result = "<html><body>\n"
result = result .. "<p> Hello Wsapi !</p>\n"
result = result .. "<p>PATH_INFO wsapi_env: " .. wsapi_env.PATH_INFO .. "</p>\n"
-- problematic code
local req = wsapi.request.new(wsapi_env)
if req
then
--condition to see if req was nill
result = result .. "<p>PATH INFO_POST : " .. req.POST .. "</p>\n"
result = result .. "<p>PATH INFO_GET : " .. req.GET .. "</p>\n"
else
result = result .. "<p> No request <\p>\n"
end
-- end of the problematic code
result = result .. "<p><form method=\"post\" action=\"hello.lua\">\n"
result = result .. "<textarea name=\"message\"> test </textarea>\n"
result = result .. "</form></p>\n"
result = result .. "</body></html>\n"
coroutine.yield(result)
end
return 200, headers, coroutine.wrap(hello_text)
end
return run
但是當我使用請求對象,客戶端收到一個空白頁。
如何創建和使用請求對象?
謝謝你的回答!
額外的問題:我如何重定向到另一個頁面(到同一個域上的靜態頁面)?