增加传参测试 获取url中所带的参数值并进行数据内容的解析

This commit is contained in:
wanglei 2025-10-24 15:15:45 +08:00
parent 839fbf4d78
commit d22570eaaf
2 changed files with 18 additions and 3 deletions

View File

@ -12,6 +12,15 @@ local validator = require("util.validator")
--获取所有用户信息
function _M.get_alluser()
--获取页码和请求的数据量
local page = 0
local pagesize = 0
local payloads = ngx.req.get_uri_args()
for k,v in pairs(payloads) do
if k == "page" then page = v end
if k == "pagesize" then pagesize = v end
end
--ngx.say("page:", page, " pagesize:", pagesize)
local code,ret = dao.getAllUser()
local result = resp:json(code, ret)
resp:send(result)

View File

@ -14,10 +14,16 @@
--max =a and b or c--a?b:c
local cjson = require("cjson")
local header = ngx.req.get_header()
local payload = ngx.req.get_payload()
local header = ngx.req.get_headers()
for k,v in pairs(header) do
ngx.say("[header] name:", k, "value:", v)
end
local payloads = ngx.req.get_uri_args()
for k,v in pairs(payloads) do
ngx.say("[params] name:", k, " value:", v)
end
ngx.say("payload:", payload)
--去掉组装最后一位逗号(,)
--local newKeys = keys:sub(1, #keys -1)
--local newValues = values:sub(1, #values -1)