Prashanth Sethalli has asked for the wisdom of the Perl Monks concerning the following question:

Hi Perl Frieds, I am very new to perl world, i am writing a perl script to login in to page which expects username and password and after login in read the content of the next page. i have been getting the Authorisation failed message for the below code, please help the same user name and password works well in the browser Obviously i have removed username and password in the below code

#!/usr/bin/perl use strict; use warnings; use LWP::UserAgent; use HTTP::Request::Common; use HTTP::Cookies; my $user=""; my $pass=""; my $url="http://news.bankofamerica.com/EOS/EosDispatcher"; # define user agent my $ua=LWP::UserAgent->new(); $ua->agent("USER/AGENT/IDENTIFICATION"); # make request my $request=HTTP::Request->new(GET=>$url) or die "request failed : $!" +; # authenticate $request->authorization_basic($user,$pass) or die "Authorisation faile +d : $!"; # expect response my $response= $ua->request($request); print $response->content();

Replies are listed 'Best First'.
Re: Logon Faied
by davido (Cardinal) on Feb 28, 2014 at 14:59 UTC

    You might want to at least read the SYNOPSIS from HTTP::Cookies. I don't see where you're creating a cookie jar, and associating it with your browser. So you've got the "use HTTP::Cookies;" part out of the way, but you're not actually doing anything with the module. It's possible that your browser must accept cookies to log in (that's pretty common).


    Dave

Re: Logon Faied
by Anonymous Monk on Mar 01, 2014 at 02:34 UTC

      Hi I have now using Mechanise and I get the following error.. PLEASE HELP I HAVE ADDED DEBUG INFORMATION ALSO

      C:\myperl>perl Mech.pl $VAR1 = 'eosftn', 'lgpwdh', 'eossbftn', 'lgid', 'lgpswd' ;

      Cache-Control: no-cache="set-cookie, set-cookie2" Connection: close Date: Mon, 03 Mar 2014 16:19:14 GMT Server: Sun-ONE-Web-Server/6.1 Content-Language: en-US Content-Type: text/html;charset=ISO-8859-1 Expires: Thu, 01 Dec 1994 16:00:00 GMT Client-Date: Mon, 03 Mar 2014 16:19:14 GMT Client-Peer: 171.197.163.162:80 Client-Response-Num: 1 Link: <style/news_styles.css>; rel="stylesheet"; type="text/css" Set-Cookie: JSESSIONID=00005gaiknLGdCJtu4uHOjs8SHo:176tso1vn; Path=/; HttpOnly Set-Cookie: BIGipServernews=1370667691.54646.0000; path=/ Title: X-Powered-By: Servlet/3.0

      POST http://news.bankofamerica.com/EOS/EosDispatcher login1 eosftn=logent (hidden readonly) lgpwdh= (hidden readonly) eossbftn= (hidden readonly) lgid= (text) lgpswd= (password) <NONAME>=Login (submit) No clickable input with name Login at C:/Perl/lib/WWW/Mechanize.pm line 1707.

      use strict; use warnings; use HTTP::Request; use HTTP::Cookies; use WWW::Mechanize; use Data::Dumper; BEGIN { $ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = 0 } #my $url="https://lonclsscwb01.emea.bankofamerica.com/paypluspce/Index +.htm"; my $url="http://news.bankofamerica.com/EOS/EosDispatcher"; my $mech = WWW::Mechanize->new(); $mech->cookie_jar(HTTP::Cookies->new()); $mech->get($url); my @forms=$mech->forms; foreach my $form (@forms) { my @inputfields = $form->param; print Dumper \@inputfields; } print $mech->dump_headers(); print $mech->dump_forms(); $mech->form_name('login1'); $mech->field ('lgid' => ''); $mech->field ('lgpswd' => ''); #my $result = $mech->submit_form( #form_name => 'login1', #name of the form #instead of form name you can specify #form_number => 1, #fields => #{ # lgid => '', # name of the input field and value # lgpswd => '', #} #,button => 'btnLogin' #name of the submit button #); #print $mech->current_form(); $mech->click('Login'); #print $mech->content();
Re: Logon Faied
by locked_user sundialsvc4 (Abbot) on Feb 28, 2014 at 18:20 UTC

    What I would do, first, is to crank up a nice debugger (like Firebug for Firefox ...) in the web-browser, so that you can w-a-t-c-h the exchanges that take place for a successful login, or for an unsuccessful one, and also for logoff.   For example, are “authorization headers” used by this web-site, or does something else happen?   Does it (as expected) set a cookie?   Once you can clearly see what the target web-site expects and does, you can create LWP code to do that.   But first you have to understand the target.   Every one is typically a little bit, uhh, atypical.   ;-)