Advertisement
Guest User

sdsdsd

a guest
Aug 21st, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JSON 0.89 KB | None | 0 0
  1. local http = require("socket.http")
  2. local ltn12 = require("ltn12")
  3.  
  4. -- The Request Bin test URL: http://requestb.in/12j0kaq1
  5. function sendRequest()
  6. local path = "http://requestb.in/12j0kaq1?param_1=one&param_2=two&param_3=three"
  7.   local payload = [[ {"key":"My Key","name":"My Name","description":"The description","state":1} ]]
  8.   local response_body = { }
  9.  
  10.   local res, code, response_headers, status = http.request
  11.   {
  12.     url = path,
  13.     method = "POST",
  14.     headers =
  15.     {
  16.       ["Authorization"] = "Maybe you need an Authorization header?",
  17.       ["Content-Type"] = "application/json",
  18.       ["Content-Length"] = payload:len()
  19.     },
  20.     source = ltn12.source.string(payload),
  21.     sink = ltn12.sink.table(response_body)
  22.   }
  23.   luup.task('Response: = ' .. table.concat(response_body) .. ' code = ' .. code .. '   status = ' .. status,1,'Sample POST request with JSON data',-1)
  24. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement