'Add body to luasocket POST request with generic form?
From https://w3.impa.br/~diego/software/luasocket/http.html, there are two ways to make a request, simple and generic. I have gotten the body to work with the simple method. However, when I add an LTN12 source to the generic method, an empty body is sent to the server.
http.request(url [, body])
http.request{
url = string,
[sink = LTN12 sink,]
[method = string,]
[headers = header-table,]
[source = LTN12 source],
[step = LTN12 pump step,]
[proxy = string,]
[redirect = boolean,]
[create = function]
}
This works:
http.request("http://localhost:56218/sendState", "at=" .. AT)
This doesn't:
local reqbody = "hi"
local respbody = {}
local body, code, headers, status = http.request {
url = "http://localhost:56218/sendState",
source = ltn12.source.string(reqBody),
headers = {
["content-length"] = string.len(reqbody)
}
sink = ltn12.sink.table(respbody)
}
When I try to read the body of the above line of code in my server, it is empty. What am I doing wrong?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
