PERL Gurus out there... I can use the RESTful API to change a variable from my browser. But, when I place the same URL in a PERL script, it fails. Here is the script
- Code: Select all
#!/usr/bin/perl
use LWP::UserAgent;
use HTTP::Request;
my $URL = 'http://127.0.0.1:8176/variables/foo?_method=put&value=bar';
my $agent = LWP::UserAgent->new(env_proxy => 1,keep_alive => 1, timeout => 30);
my $header = HTTP::Request->new(GET => $URL);
my $request = HTTP::Request->new('GET', $URL, $header);
my $response = $agent->request($request);
# Check the outcome of the response
if ($response->is_success){
print "URL:$URL\nHeaders:\n";
print $response->headers_as_string;
print "\nContent:\n";
print $response->as_string;
}elsif ($response->is_error){
print "Error:$URL\n";
print $response->error_as_HTML;
}
and running it produce this result
- Code: Select all
Error:http://127.0.0.1:8176/variables/foo?_method=put&value=bar
<html>
<head><title>An Error Occurred</title></head>
<body>
<h1>An Error Occurred</h1>
<p>401 Unauthorized</p>
</body>
</html>
Any ideas as to the cause of the 402 error? I did try adding my username:password to the URL, but that didn't work either.