Description
Hello,
I have an issue while trying to send HTTP POST request to remote host. I get "closed" error message and I can't understand what is the problem.
This is my code:
local httpc = http.new()
httpc:set_timeout(5000)
local request_body = "id=myId¶m2=key2¶m3=key3"
local req_len = string.len(request_body)
local ok, err = httpc:connect({
scheme = "https",
host = "100.0.0.0",
port = 443,
ssl_verify = false
})
if not ok or err then
ngx.log(ngx.NOTICE, "Error while connecting to remote host " .. err)
return ngx.exit(500)
end
--- Here I get closed error message, response is nil
local response, err = httpc:request({
path = '/api/client',
method = 'POST',
body = request_body,
headers = {
["Content-Type"] = "application/x-www-form-urlencoded",
["Content-Length"] = req_len,
["Host"] = "100.0.0.0"
}
})
if err then
ngx.log(ngx.NOTICE, "Error while sending req remote host " .. err)
return ngx.exit(500)
end
if not response or response["status"] ~= 200 or not response["body"] then
ngx.log(ngx.NOTICE, "Failed to send req to remote host " .. err)
return ngx.exit(500)
end
the "connect" succeeded but when I execute the request command I got the error.
I verified that the content-length is correct.
I also tried to use requesturi but got the same error.
The request body is form data.
What do I miss?
Thank you,
Barak.