0

I am trying to login into an URL using LWP perl

My URL open ups with a pop up asking for username and password.When I try to manually log in ,it succeeds but through LWP,I am getting 401 error

my ($url) = @_;
my $ua = LWP::UserAgent->new( keep_alive => 1, agent => "Mozilla/4.76 " );
push @{ $ua->requests_redirectable }, 'POST';
$ua->cookie_jar( HTTP::Cookies->new( file => "$ENV{HOME}/.cookies.txt" ) );

# timeout:
$ua->timeout(30);
print "\nMaking request to $url\n";

my $request = HTTP::Request->new('GET');
$request->url($url);
my $response = $ua->request($request);
    my $user = "weblogic";
    my $pwd  = "Fusionapps1";
    $ua->credentials( $url, "default", $user, $pwd );
    #$request->authorization_basic( $user, $pwd );
    my $response = $ua->request($request);
    if ( $response->is_success ) {
        $isLoginSuccessful = 1;
    }

} 

I have tried with the below thing as well

$request->authorization_basic( $user, $pwd );

ERROR: Error 401--Unauthorized

Kindly help!! Any help will be appreciated

Sammidbest
  • 463
  • 2
  • 10
  • 20

1 Answers1

0

To interact with a website and fill out forms such as logins, I suggest that you use WWW::Mechanize.

Note, if the website contains JavaScript, you'll have to use something like WWW::Mechanize::Firefox.

Miller
  • 34,962
  • 4
  • 39
  • 60
  • It sounds like the OP may actually be talking about Basic Authentication, in which case there is no actual form to fill. But +1 to WWW::Mechanize in general. – oalders Jun 11 '14 at 14:36