ngx_lua 模块很方便嵌入nginx 里,该模块获取post 或 get 参数也很方便
获取post 或 get 参数的lua 代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
local request_method = ngx.var.request_method
--获取参数的值
if request_method == "GET" then
local args, err = ngx.req.get_uri_args()
elseif request_method == "POST" then
ngx.req.read_body() -- 关键是这一行
local args, err = ngx.req.get_post_args()
end
if not args then
ngx.say("failed to get post args: ", err)
return
end
for key, val in pairs(args) do
if type(val) == "table" then
ngx.say(key, ": ", table.concat(val, ", "))
else
ngx.say(key, ": ", val)
end
end
接口参考
本文网址: https://pylist.com/topic/116.html 转摘请注明来源