Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

closed error when sending request #302

Open
barakpp opened this issue Sep 20, 2023 · 0 comments
Open

closed error when sending request #302

barakpp opened this issue Sep 20, 2023 · 0 comments

Comments

@barakpp
Copy link

barakpp commented Sep 20, 2023

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&param2=key2&param3=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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant