$browser->credentials(
'servername:portnumber',
'realm-name',
'username' => 'password'
);
In most cases, the port number is 80, the default TCP/IP port for
HTTP. For example:
my $browser = LWP::UserAgent->new;
$browser->name('ReportsBot/1.01');
$browser->credentials(
'reports.mybazouki.com:80',
'web_server_usage_reports',
'plinky' => 'banjo123'
);
my $response = $browser->get(
'http://reports.mybazouki.com/this_week/'
);
One can call the credentials method any number of
times, to add all the server-port-realm-username-password keys to the
browser's key ring, regardless of whether
they'll actually be needed. For example, you could
read them all in from a datafile at startup:
my $browser = LWP::UserAgent->new( );
if(open(KEYS, "< keyring.dat")) {
while(<KEYS>) {
chomp;
my @info = split "\t", $_, -1;
$browser->credential(@info) if @info == 4;
};
close(KEYS);
}