【发布时间】:2023-01-27 17:44:59
【问题描述】:
我正在尝试使用 luasec 在 lua 中发布一些 json 数据,但是在下面的例子中,看起来没有数据被发送。它甚至发生在 GET 请求中。也许我没有正确使用 ltn12?
这是我试过的代码:
local ltn12 = require('ltn12')
local https = require('ssl.https')
local json = require("json")
local body = json.encode({
test = "test ok"
})
local r = {}
https.request {
url = 'https://httpbin.org/anything',
method = "POST",
headers = {["Content-Type"] = "application/json"},
source = ltn12.source.string(body),
sink = ltn12.sink.table(r)
}
print(r[1])
结果如下:
{
"args": {},
"data": "",
"files": {},
"form": {},
"headers": {
"Content-Type": "application/json",
"Host": "httpbin.org",
"User-Agent": "LuaSocket 3.0-rc1",
"X-Amzn-Trace-Id": "..."
},
"json": null,
"method": "POST",
"origin": "XX.XX.XX.XX",
"url": "https://httpbin.org/anything"
}
“数据”字段为空。
【问题讨论】: