Powershell and JSON with basic-auth?

All kinds of 'OS' scripts
Post Reply
Evelen
Posts: 269
Joined: Thursday 09 July 2015 12:03
Target OS: Linux
Domoticz version: 2.4538
Location: Norway
Contact:

Powershell and JSON with basic-auth?

Post by Evelen » Monday 06 February 2017 1:08

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)

Evelen
Posts: 269
Joined: Thursday 09 July 2015 12:03
Target OS: Linux
Domoticz version: 2.4538
Location: Norway
Contact:

Re: Powershell and JSON with basic-auth?

Post by Evelen » Monday 06 February 2017 2:03

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

Evelen
Posts: 269
Joined: Thursday 09 July 2015 12:03
Target OS: Linux
Domoticz version: 2.4538
Location: Norway
Contact:

Re: Powershell and JSON with basic-auth?

Post by Evelen » Thursday 09 February 2017 20:53

Still don't know how to POST..
EDIT: Now I know.
same as GET, with GET

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest