local cjson = require "cjson" local http = require "resty.http" 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(files, authHeader, sudoerToken) local httpc = http.new() 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) local body_text = cjson.encode({ task_type = TaskTypes.UPLOAD_PICTURE, payload = { images = files } }) ngx.log(ngx.INFO, 'UPLOAD_PICTURE *body_text* ->', body_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 = body_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.say(res.body) ngx.exit(res.status) end return create_task