Openresty gets request parameters

  openresty

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:

?strider=1&strider=2&strider=3&strider=4

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

ngx.req.read_body()
local postargs = ngx.req.get_post_args()
postargs["user_id"]

doc