Page 1 of 1

Powershell and JSON with basic-auth?

Posted: Monday 06 February 2017 0:08
by Evelen
Hi.

Two fast questins about Powershell and Domoticz:
- How to GET JSON from domoticz when using basic-auth? (if i want to si if a lamp is on)
- How to POST JSON from domoticz when using basic-auth? (if i want to set a lamp to on)

Re: Powershell and JSON with basic-auth?

Posted: Monday 06 February 2017 1:03
by Evelen
For GET, this worked:

Code: Select all

$user = "username"
$pass = "password"
$pair = "${user}:${pass}"
$bytes = [System.Text.Encoding]::ASCII.GetBytes($pair)
$base64 = [System.Convert]::ToBase64String($bytes)
$basicAuthValue = "Basic $base64"
$headers = @{ Authorization = $basicAuthValue }
$json_info = Invoke-WebRequest -uri "http://192.168.1.123:8080/json.htm?type=devices&rid=139" -Headers $headers
Write-Host innholdet er $Json_info.Content
http://stackoverflow.com/questions/2795 ... ation-on-t

Re: Powershell and JSON with basic-auth?

Posted: Thursday 09 February 2017 19:53
by Evelen
Still don't know how to POST..
EDIT: Now I know.
same as GET, with GET