post
res = ngx.location.capture('/update',{method = ngx.HTTP_POST,body = "name=" .. name .. "&content=" .. content})
解析json
local cjson = require("cjson")
local data = cjson.decode(res.body)
如果返回的不是json格式,则这段lua脚本会报错
Expected value but found invalid token at character 1
stack traceback:
coroutine 0:
[C]: in function 'decode'
安全解析json
local cjson = require("cjson.safe")
local data = cjson.decode(res.body)
if data==nil then
--....
end