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

 

 

posted @ 2014-06-10 13:44  缤纷世界  阅读(5798)  评论(0编辑  收藏  举报