#!/exlibris/metalib/m4_8/product/bin/perl use strict; use LWP::UserAgent; use URI::Escape; use HTTP::Cookies; my ($session,$view_state,$t,$d,$event_validation,$new_view_state,$session_enc,$login); my $ua = new LWP::UserAgent; $ua->cookie_jar(HTTP::Cookies->new()); #### First call - go to the home page and get the initial session ID my $search_command = "http://www.everydaylife.amdigital.co.uk"; my $req = new HTTP::Request('GET',$search_command); my $res = $ua->request($req); my $response = $res->headers_as_string(); my $response .= $res->content; print "Cookies after 1st transaction:".$ua->cookie_jar->as_string."\n"; ########################################################################## ##### Parse a few parameters for the following requests' authentication if($response =~ /action="Login.aspx\?sessionID=(.*?)&originalURL=/){ $session = $1; } if($response =~ /id="__VIEWSTATE"\s*value="(.*?)"/){ $view_state = $1; } if($response =~ /id="__EVENTVALIDATION" value="(.*?)"/){ $event_validation = $1; } ########################################################################### #### Second call - use the parameters we found and perform a POST request ##The search address my $search_command = "http://secure.amdigital.co.uk/Login.aspx?sessionID=$session&originalURL=http%3a%2f%2fwww.everydaylife.amdigital.co.uk%2findex.aspx"; ##The POST content my $content = "__EVENTTARGET=&__EVENTARGUMENT=&__VIEWSTATE=$view_state&UserNameTextBox=EXLIBRIS&PasswordTextbox=EXLIBRIS&LoginButton=Login&__EVENTVALIDATION=$event_validation"; ##The headers my $header = new HTTP::Headers( 'Accept-Language' => 'en-us', 'Content-Type' => 'application/x-www-form-urlencoded', 'User-Agent' => 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)', 'Connection' => 'Keep-Alive', 'Cache-Control' => 'no-cache', ); $req = new HTTP::Request('POST',$search_command,$header,$content); $res = $ua->request($req); ##The cookie jar print "Cookies after 2nd transaction:".$ua->cookie_jar->as_string."\n";