--local cjson = require "cjson" -- --local TaskTypes = { -- NOOP = 'NOOP', -- UPLOAD_PICTURE = 'UPLOAD_PICTURE' --} local task_server = ngx.var.task_server local htyhost = ngx.req.get_headers().HtyHost ngx.log(ngx.INFO, "TASK_SERVER -> ", task_server) ngx.log(ngx.INFO, "HTY HOST -> ", htyhost) local function create_task(httpc, task_text, authHeader, sudoerToken) local remote_url = string.format("%s/api/v1/ts/create_task", task_server) ngx.log(ngx.INFO, 'remote_url -> ', remote_url) ngx.log(ngx.INFO, 'Authorization -> ', authHeader) ngx.log(ngx.INFO, 'HtySudoerToken -> ', sudoerToken) ngx.log(ngx.INFO, 'UPLOAD_PICTURE *body_text* ->', task_text) local res, err = httpc:request_uri( remote_url, { ssl_verify = false, -- 设置参数 ssl_verify 为false 不校验ssl证书 method = "POST", headers = { ["Content-Type"] = "application/json", ["Authorization"] = authHeader, ["HtySudoerToken"] = sudoerToken, ['HtyHost'] = htyhost }, body = task_text, } ) if res == nil then ngx.log(ngx.ERR, "FAILED TO CONNECT TO *TASK_SERVER*", err) end if 201 ~= res.status then ngx.log(ngx.ERR, "TASK CREATE *FAILED*", res.body) end -- 必须先显示设置ngx.status,因为ngx.say会默认设置status为200 -- 后面再在ngx.exit里指定status就会出现冲突,报下面错误: -- attempt to set status 401 via ngx.exit after sending out the response status 200 ngx.status = res.status ngx.say(res.body) ngx.exit(res.status) end return create_task