且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

HttpLuaModule 获取Get和Post参数

更新时间:2021-07-15 11:17:50

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"))