cjson = require "cjson" ngx. req. read_body() -- explicitly read the req body local data = ngx. req. get_body_data() local jsonBody = cjson. decode(data); if data then local reqs = { } --ngx. say("body data:") for key, value in pairs(jsonBody) do --ngx.print(key) --ngx.print(value.url) local param = { } param["args"] = value.query local method = ngx.HTTP_GET if value.method == "POST" then method = ngx.HTTP_POST param["body"] = value.body end param["method"] = method local reqParam = { } reqParam[1] = value.url reqParam[2] = param table.insert(reqs, reqParam) end local resps = {ngx.location.capture_multi(reqs)} local reponseData = {} -- loop over the responses table for key, value in pairs(resps) do -- process the response table "resp" -- ngx.print(key) -- ngx.print(value.body) --ngx.say(jsonBody[key].url) local theUrl = jsonBody[key].url reponseData[theUrl] = value.body end local responseJson = cjson.encode(reponseData) ngx.header["Content-Type"] = "application/json; charset=UTF-8" ngx.say(responseJson) end