21.04.2020, 11:16
JSON post example:
Code:
function post(url, body)
local ltn12 = require('ltn12')
local https = require('ssl.https')
local sink = {}
local res, err = https.request({
url = url,
method = 'POST',
headers = {
['Content-Length'] = #body,
['Content-Type'] = 'application/json',
},
sink = ltn12.sink.table(sink),
source = ltn12.source.string(body),
})
if res then
return table.concat(sink)
else
return nil, err
end
end
require('json')
url = 'https://postman-echo.com/post'
body = json.encode({ value1 = '123' })
res, err = post(url, body)