您的位置:首页 > 理论基础 > 计算机网络

HttpLuaModule 获取Get和Post参数

2014-06-10 13:44 501 查看
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"))
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: