I am trying to request an html document with HTTPS authentication using Perl. I haven't had an issue with non-HTTPS code in the past. I'm currently using LWP::UserAgent:
#! /usr/bin/perl
use LWP;
use HTTP::Request::Common;
my $browser = LWP::UserAgent->new;
my $baseurl = "https://xyz.url.com/directory";
my $ua = LWP::UserAgent->new(keep_alive=>1);
$ua->cookie_jar({});
$ua->credentials('xyz.url.com:80', '', 'login', 'password');
my $response = $ua->get($baseurl);
print $response->content();
The response that is printed is essentially the '401 Unauthorized' page. I am able to login via the browser. The browser uses a pop-up that reads 'Authentication Required -- The server xyz.url.com:80 requires a username and password. The server says: Blah Blah' I have read many posts instructing to install things like Crypt::SSLeay
and LWP::Protocol::https
. These are installed. I'm stumped.
I've also downloaded a program called Charles to see if there is anything of note with the request/response, however I'm not really sure where to look. I've tried adding 'Blah Blah' for the realm, but this wasn't successful. Can the realm be identified using Charles?
The documentation says that the first argument to credentials is <host>:<port>
— that is, the port number isn't optional. Try "xyz.url.com:443"
. Also, a realm of ''
isn't going to be valid unless that's what the server is sending; you actually want to use "Blah Blah"
for the realm, I believe.