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.

Digest Auth - JSON
#9
(19.07.2023, 13:04)admin Wrote: Try passing username/password like in this example: https://forum.logicmachine.net/showthrea...8#pid26618
Try both username variants - with @ and %40.

Yes that works like a charm Smile

Code:
http = require('socket.http')
mime = require('mime')
json = require('json')

result = http.request({
  url = 'http://api.huum.eu/action/home/status',
  headers = {
    Authorization = 'Basic ' .. mime.b64('username:password')
  }
})

data = json.pdecode(result)

log(data)

And now my next question is how to send a JSON POST command?

The url is then: https://api.huum.eu/action/home/start
And the JSON command: {'targetTemperature' : 80}

(19.07.2023, 13:55)Joep Wrote:
(19.07.2023, 13:04)admin Wrote: Try passing username/password like in this example: https://forum.logicmachine.net/showthrea...8#pid26618
Try both username variants - with @ and %40.

Yes that works like a charm Smile

Code:
http = require('socket.http')
mime = require('mime')
json = require('json')

result = http.request({
  url = 'http://api.huum.eu/action/home/status',
  headers = {
    Authorization = 'Basic ' .. mime.b64('username:password')
  }
})

data = json.pdecode(result)

log(data)

And now my next question is how to send a JSON POST command?

The url is then: https://api.huum.eu/action/home/start
And the JSON command: {'targetTemperature' : 80}

I already found the solution. Smile

Code:
function post(url, body)
  local ltn12 = require('ltn12')
  local http = require('socket.http')
  local sink = {}
  local res, err = http.request({
    url = url,
    method = 'POST',
    headers = {
      ['Authorization'] = 'Basic '..(mime.b64('username:password')),
      ['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://api.huum.eu/action/home/start'
body = '{"targetTemperature" : 70}'
result = post(url, body)
data = json.pdecode(result)
log(data)
Reply


Messages In This Thread
Digest Auth - JSON - by Krstfr2k - 08.01.2021, 11:04
RE: Digest Auth - JSON - by admin - 11.01.2021, 08:04
RE: Digest Auth - JSON - by Joep - 15.07.2023, 14:44
RE: Digest Auth - JSON - by Joep - 15.07.2023, 15:58
RE: Digest Auth - JSON - by Joep - 17.07.2023, 15:17
RE: Digest Auth - JSON - by admin - 17.07.2023, 15:20
RE: Digest Auth - JSON - by Joep - 19.07.2023, 12:52
RE: Digest Auth - JSON - by admin - 19.07.2023, 13:04
RE: Digest Auth - JSON - by Joep - 19.07.2023, 13:55

Forum Jump: