Openresty gets request parameters


Get url parameters

Ngx.var.arg_xx and ngx.req.get_uri_args[“xx”] are both to obtain parameters in the request uri, for example

? strider=1
In order to obtain the input parameter strider, the following two methods can be used:

local strider = ngx.var.arg_strider
local strider = ngx.req.get_uri_args["strider"]

The difference is that when there are multiple parameters with the same name in the request uri, ngx.var.arg_xx takes the first value that appears, and ngx.req_get_uri_args[“xx”] returns a table in which all the values of the parameter are stored, for example, when the request uri is:


Ngx.var.arg_strider has a value of “1”, while ngx.req.get _ uri _ args [“strider”] has a value of table [“1”, “2”, “3”, “4”].

Therefore, ngx.req.get_uri_args belongs to the enhancement of ngx.var.arg_

Get post parameters

local postargs = ngx.req.get_post_args()