HttpLuaModule 获取Get和Post参数

简介: Get方式: local id = tostring(ngx.var.arg_id) local type = tostring(ngx.var.arg_type) Post方式: ngx.

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

 

 

相关文章
|
25天前
|
网络协议 数据安全/隐私保护
get和post的区别
get和post的区别
19 0
|
4月前
|
JSON 数据格式
Nestjs(三)接收参数 @Query @Body @Param(post、get 、put、delete ...)
Nestjs(三)接收参数 @Query @Body @Param(post、get 、put、delete ...)
164 4
|
8天前
|
Web App开发 缓存 网络协议
get和post的区别!
get和post的区别!
Kam
|
Java Maven
Feign调用把GET请求自动转成POST请求解决:Request method 'POST' not supported
Feign调用把GET请求自动转成POST请求解决:Request method 'POST' not supported
Kam
1601 0
|
8月前
|
缓存
get和post的区别
`GET` 和 `POST` 是 HTTP 请求方法,常用于客户端(如浏览器)与服务器之间的通信。
|
4月前
|
缓存 安全 数据安全/隐私保护
GET和POST有什么区别
GET和POST有什么区别
|
10月前
|
网络协议 安全 数据安全/隐私保护
GET与POST的区别
GET与POST的区别
97 0
|
网络协议 安全
GET 和 POST 的区别
GET 和 POST 的区别
104 0
|
缓存 安全 前端开发
GET和POST有什么区别?
GET和POST有什么区别?
GET和POST有什么区别?
|
网络协议
get和post区别是什么?
get和post区别是什么?
149 0