【发布时间】:2022-08-16 02:24:39
【问题描述】:
从https://w3.impa.br/~diego/software/luasocket/http.html 开始,有两种方法可以发出请求,简单和通用。我已经让身体用简单的方法工作了。但是,当我将 LTN12 源添加到通用方法时,会向服务器发送一个空正文。
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]
}
这有效:
http.request(\"http://localhost:56218/sendState\", \"at=\" .. AT)
这不会:
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)
}
当我尝试在我的服务器中读取上述代码行的正文时,它是空的。我究竟做错了什么?
标签: http post lua request luasocket