#!/usr/bin/perl { package DINAgent; use strict; use warnings; use base 'LWP::UserAgent'; sub get_basic_credentials { return ('admin','password'); } } require 5.010_001; use strict; use warnings; use HTTP::Request; use Encode qw(encode_utf8); use LWP::ConsoleLogger::Everywhere (); my $ip = '192.168.54.24'; my $url = "http://".$ip."/restapi/relay/outlets/=4/state/"; my $header = [ 'X-CSRF' => 'x', 'Accept' => 'application/json', 'Content-Type' => 'application/x-www-form-urlencoded', ]; my $data = encode_utf8('value=true'); my $req = HTTP::Request->new('GET', $url, $header, $data); my $ua = DINAgent->new; my $res = $ua->request($req); #### GET http://192.168.54.24/restapi/relay/outlets/=4/state/ .---------------------------------+-------------------------------------------------. | Request (before sending) Header | Value | +---------------------------------+-------------------------------------------------+ | Accept | application/json | | Authorization | Digest username="admin", realm="DLI DIN4181200- | | | 5889", qop=auth, algorithm="MD5", uri="/restap- | | | i/relay/outlets/=4/state/", nonce="lUbDs5U7hoG- | | | pVuUw", nc=00000001, cnonce="5ad8c8da", respon- | | | se="9b02b9381e1ce4b8de39d2d00d176926", opaque=- | | | "poDELG+OAifnQbRd" | | Content-Type | application/x-www-form-urlencoded | | User-Agent | libwww-perl/6.33 | | X-CSRF | x | '---------------------------------+-------------------------------------------------' .------------. | Content | +------------+ | value=true | '------------' .--------------------------. | Text | +--------------------------+ | { | | value => "true", | | } | '--------------------------' .--------------------------------+--------------------------------------------------. | Request (after sending) Header | Value | +--------------------------------+--------------------------------------------------+ | Accept | application/json | | Authorization | Digest username="admin", realm="DLI DIN41812005- | | | 889", qop=auth, algorithm="MD5", uri="/restapi/- | | | relay/outlets/=4/state/", nonce="lUbDs5U7hoGpVu- | | | Uw", nc=00000001, cnonce="5ad8c8da", response="- | | | 9b02b9381e1ce4b8de39d2d00d176926", opaque="poDE- | | | LG+OAifnQbRd" | | Content-Type | application/x-www-form-urlencoded | | User-Agent | libwww-perl/6.33 | | X-CSRF | x | '--------------------------------+--------------------------------------------------' ==> 207 Responses from multiple resources follow #### PUT http://192.168.54.24/restapi/relay/outlets/=4/state/ .---------------------------------+-------------------------------------------------. | Request (before sending) Header | Value | +---------------------------------+-------------------------------------------------+ | Accept | application/json | | Authorization | Digest username="admin", realm="DLI DIN4181200- | | | 5889", qop=auth, algorithm="MD5", uri="/restap- | | | i/relay/outlets/=4/state/", nonce="/TiSJpxNOX2- | | | YUGF9", nc=00000001, cnonce="5ad8c6b2", respon- | | | se="4d899287d76eeb9544e1f74398a75189", message- | | | -digest="d41d8cd98f00b204e9800998ecf8427e", op- | | | aque="32bmBh1vwolMgswm" | | Content-Type | application/x-www-form-urlencoded | | User-Agent | libwww-perl/6.33 | | X-CSRF | x | '---------------------------------+-------------------------------------------------' .------------. | Content | +------------+ | value=true | '------------' .--------------------------. | Text | +--------------------------+ | { | | value => "true", | | } | '--------------------------' .--------------------------------+--------------------------------------------------. | Request (after sending) Header | Value | +--------------------------------+--------------------------------------------------+ | Accept | application/json | | Authorization | Digest username="admin", realm="DLI DIN41812005- | | | 889", qop=auth, algorithm="MD5", uri="/restapi/- | | | relay/outlets/=4/state/", nonce="/TiSJpxNOX2YUG- | | | F9", nc=00000001, cnonce="5ad8c6b2", response="- | | | 4d899287d76eeb9544e1f74398a75189", message-dige- | | | st="d41d8cd98f00b204e9800998ecf8427e", opaque="- | | | 32bmBh1vwolMgswm" | | Content-Type | application/x-www-form-urlencoded | | User-Agent | libwww-perl/6.33 | | X-CSRF | x | '--------------------------------+--------------------------------------------------' ==> 401 Unauthorized