This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Send notifications via pushover
#11
(01.02.2018, 15:37)bmodeco Wrote:
(01.02.2018, 13:09)admin Wrote: Try this, I've tested it with nginx and apache so other servers might reject this request. Fill params table with your post arguments, filedata variable should contain binary data of your jpeg image, set request url as needed.

Code:
require('ssl.https')

boundary = os.date('%d%m%Y%H%M%S')

params = {
 {
   name = 'token',
   value = '12345',
 },
 {
   name = 'user',
   value = 'testuser',
 },
 {
   name = 'attachment',
   filename = 'snapshot.jpg',
   ctype = 'image/jpeg',
   value = filedata,
 }
}

body = { '--' .. boundary }

for _, param in ipairs(params) do
 line = string.format('Content-Disposition: form-data; name=%q', param.name)
 if param.filename then
   line = string.format('%s; filename=%q', line, param.filename)
 end
 body[ #body + 1 ] = line

 if param.ctype then
   body[ #body + 1 ] = string.format('Content-Type: %s', param.ctype)
 end

 body[ #body + 1 ] = ''
 body[ #body + 1 ] = param.value
 body[ #body + 1 ] = '--' .. boundary
end

-- last boundary
body[ #body ] = body[ #body ] .. '--'
-- empty line at the end
body[ #body + 1 ] = ''

bodydata = table.concat(body, '\r\n')

resp = {}

log(
 ssl.https.request({
   url = 'https://...',
   sink = ltn12.sink.table(resp),
   method = 'POST',
   source = ltn12.source.string(bodydata),
   headers = {
     ['content-length'] = #bodydata,
     ['content-type'] = 'multipart/form-data; boundary=' .. boundary
   }
 })
)

log(table.concat(resp))

Thanks admin for the fast response! Will try it out.
Thanks I will try it.
local data_str = 'token=token&user=user&device=gsm&message=test&attachment='??????'&title=LogicMachine&sound=bike&priority=0'

local res, code, headers, status = ssl.https.request(pushover_url, data_str)
Reply


Messages In This Thread
RE: Send notifications via pushover - by Keitz - 01.02.2018, 17:03

Forum Jump: