HttpLuaModule 获取Get和Post参数

时间:2023-03-09 20:01:28
HttpLuaModule 获取Get和Post参数

Get方式:

local id = tostring(ngx.var.arg_id)
local type = tostring(ngx.var.arg_type)

Post方式:

ngx.req.read_body()
local args = ngx.req.get_post_args()
local id = tostring(args["id"])
local type = tostring(args["type"])

两种方式混合

local request_method = ngx.var.request_method
local args = nil
if "GET" == request_method then
nginx.say("Get")
args = ngx.req.get_uri_args()
else
nginx.say("Post")
ngx.req.read_body()
args = ngx.req.get_post_args()
end local id = tostring(args["id"])
local type = tostring(args["type"])

【其他备忘】

获取IP地址

local ip_addr = tostring(ngx.var.remote_addr)

当前时间

tostring(os.date("%Y-%m-%d %H:%M:%S"))