Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local http = require("socket.http")
- local ltn12 = require("ltn12")
- -- The Request Bin test URL: http://requestb.in/12j0kaq1
- function sendRequest()
- local path = "http://requestb.in/12j0kaq1?param_1=one¶m_2=two¶m_3=three"
- local payload = [[ {"key":"My Key","name":"My Name","description":"The description","state":1} ]]
- local response_body = { }
- local res, code, response_headers, status = http.request
- {
- url = path,
- method = "POST",
- headers =
- {
- ["Authorization"] = "Maybe you need an Authorization header?",
- ["Content-Type"] = "application/json",
- ["Content-Length"] = payload:len()
- },
- source = ltn12.source.string(payload),
- sink = ltn12.sink.table(response_body)
- }
- luup.task('Response: = ' .. table.concat(response_body) .. ' code = ' .. code .. ' status = ' .. status,1,'Sample POST request with JSON data',-1)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement