Example code:
location = /test/sendemail { add_header 'Content-Type' 'text/html'; content_by_lua_block { local httpc = require("resty.http").new() local body = "your-body" local res, err = httpc:request_uri("https://api.mailjet.com/v3.1/send", { ssl_verify = false, method = "POST", body = body, headers = { ["Content-Type"] = "application/json", authorization= 'Basic ...........Zjg=' } }) if not res then ngx.say(err) else local body = res.body ngx.say(body) end } }
And we see error:
no resolver defined to resolve "api.mailjet.com"
How to fix this error:
Solution 1: use directive resolver example: resolver 8.8.8.8;
in block location
Solution 2: You can add this line to file /etc/resolver.conf
nameserver 8.8.8.8