Gandalf StormCrow
Gandalf StormCrow

Reputation: 26212

Send rest request with Perl

Is it possible to send rest request, including header authentication in perl/shell script/command line. And get the response?

Upvotes: 2

Views: 3362

Answers (1)

ADW
ADW

Reputation: 4080

Something like this if you want to manipulate the result in Perl:

use strict;
use warnings;
use LWP::UserAgent;

my $ua=LWP::UserAgent->new;

my $result=$ua->get("http://www.google.com/");

print $result->content;

Or, with basic HTTP authentication something like this:

use strict;
use warnings;
use LWP::UserAgent;

my $ua=LWP::UserAgent->new;

$ua->credentials("www.pagetutor.com:80","My Secret Area","jimmy","page");

my $result=$ua->get("http://www.pagetutor.com/keeper/mystash/secretstuff.html");

print $result->content;

See http://www.pagetutor.com/keeper/http_authentication/index.html for where the password came from. Just the first random page I found which requires basic authentication.

Upvotes: 5

Related Questions