#!usr/bin/perl use strict; use warnings; require LWP::UserAgent; require HTTP::Request::Common; require HTTP::Response; use HTML::Form; use WWW::Mechanize; use MIME::Base64; my $username = 'username'; my $password = 'password'; my @args = ( Authorization => "Basic " . MIME::Base64::encode( $username . ':' . $password )); my $mech = WWW::Mechanize->new(); # I can remove the realm/host without affecting the 200 -> 401 occurance $mech->credentials( 'www.edited.com:443', 'Title', $username, $password ); # enabling cookies, I'm not sure if I even need this part use HTTP::Cookies; $mech->cookie_jar( HTTP::Cookies->new( 'file' => '~/Desktop/programming/cookies.lwp', # where to read/write cookies 'autosave' => 1, # save it to disk when done )); # the site my $url = "https://www.edited.com/disclaimer.cgi"; $mech -> get ($url, @args); # HTML prints normally print $mech->content; # then I just want to click the button B1 $mech->click_button(name => 'B1'); # just in case it was a delay issue sleep(5); # then I get a 401 error print $mech->status(), "\n";