Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
And here is the PERL code which performs the login(it prints only the cookies,without the full HTML response):http://www.everydaylife.amdigital.co.uk/ GET / HTTP/1.1 Host: www.everydaylife.amdigital.co.uk User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1 +1) Gecko/20071127 Firefox/2.0.0.11 Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9 +,text/plain;q=0.8,image/png,*/*;q=0.5 Accept-Language: en-us,en;q=0.5 Accept-Encoding: gzip,deflate Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 Keep-Alive: 300 Connection: keep-alive HTTP/1.x 302 Found Date: Thu, 06 Dec 2007 10:19:21 GMT Server: Microsoft-IIS/6.0 X-Powered-By: ASP.NET X-AspNet-Version: 1.1.4322 Location: /login.aspx?ReturnUrl=%2findex.aspx Cache-Control: private Content-Type: text/html; charset=utf-8 Content-Length: 152 ---------------------------------------------------------- http://www.everydaylife.amdigital.co.uk/login.aspx?ReturnUrl=%2findex. +aspx GET /login.aspx?ReturnUrl=%2findex.aspx HTTP/1.1 Host: www.everydaylife.amdigital.co.uk User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1 +1) Gecko/20071127 Firefox/2.0.0.11 Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9 +,text/plain;q=0.8,image/png,*/*;q=0.5 Accept-Language: en-us,en;q=0.5 Accept-Encoding: gzip,deflate Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 Keep-Alive: 300 Connection: keep-alive HTTP/1.x 302 Found Date: Thu, 06 Dec 2007 10:19:21 GMT Server: Microsoft-IIS/6.0 X-Powered-By: ASP.NET X-AspNet-Version: 1.1.4322 Location: http://secure.amdigital.co.uk/Login.aspx?sessionID=tjfxz255r +cn0ei55nskjfl55&originalURL=http%3a%2f%2fwww.everydaylife.amdigital.c +o.uk%2findex.aspx Set-Cookie: ASP.NET_SessionId=tjfxz255rcn0ei55nskjfl55; path=/ Cache-Control: private Content-Type: text/html; charset=utf-8 Content-Length: 267 ---------------------------------------------------------- http://secure.amdigital.co.uk/Login.aspx?sessionID=tjfxz255rcn0ei55nsk +jfl55&originalURL=http%3a%2f%2fwww.everydaylife.amdigital.co.uk%2find +ex.aspx GET /Login.aspx?sessionID=tjfxz255rcn0ei55nskjfl55&originalURL=http%3a +%2f%2fwww.everydaylife.amdigital.co.uk%2findex.aspx HTTP/1.1 Host: secure.amdigital.co.uk User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1 +1) Gecko/20071127 Firefox/2.0.0.11 Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9 +,text/plain;q=0.8,image/png,*/*;q=0.5 Accept-Language: en-us,en;q=0.5 Accept-Encoding: gzip,deflate Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 Keep-Alive: 300 Connection: keep-alive HTTP/1.x 302 Found Date: Thu, 06 Dec 2007 10:19:22 GMT Server: Microsoft-IIS/6.0 X-Powered-By: ASP.NET X-AspNet-Version: 2.0.50727 Location: http://secure.amdigital.co.uk/Login.aspx?sessionID=tjfxz255r +cn0ei55nskjfl55&originalURL=http%3a%2f%2fwww.everydaylife.amdigital.c +o.uk%2findex.aspx&cookiesTesting=true Set-Cookie: ASP.NET_SessionId=g534qbaix4gqne551mr1gs45; path=/; HttpOn +ly Set-Cookie: AMPCAM=cam; path=/ Cache-Control: private Content-Type: text/html; charset=utf-8 Content-Length: 291 ---------------------------------------------------------- http://secure.amdigital.co.uk/Login.aspx?sessionID=tjfxz255rcn0ei55nsk +jfl55&originalURL=http%3a%2f%2fwww.everydaylife.amdigital.co.uk%2find +ex.aspx&cookiesTesting=true GET /Login.aspx?sessionID=tjfxz255rcn0ei55nskjfl55&originalURL=http%3a +%2f%2fwww.everydaylife.amdigital.co.uk%2findex.aspx&cookiesTesting=tr +ue HTTP/1.1 Host: secure.amdigital.co.uk User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1 +1) Gecko/20071127 Firefox/2.0.0.11 Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9 +,text/plain;q=0.8,image/png,*/*;q=0.5 Accept-Language: en-us,en;q=0.5 Accept-Encoding: gzip,deflate Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 Keep-Alive: 300 Connection: keep-alive Cookie: ASP.NET_SessionId=g534qbaix4gqne551mr1gs45; AMPCAM=cam HTTP/1.x 200 OK Date: Thu, 06 Dec 2007 10:19:23 GMT Server: Microsoft-IIS/6.0 X-Powered-By: ASP.NET X-AspNet-Version: 2.0.50727 Cache-Control: private Content-Type: text/html; charset=utf-8 Content-Length: 9317 ---------------------------------------------------------- http://secure.amdigital.co.uk/Login.aspx?sessionID=tjfxz255rcn0ei55nsk +jfl55&originalURL=http%3a%2f%2fwww.everydaylife.amdigital.co.uk%2find +ex.aspx&cookiesTesting=true#1f3e7d GET /Login.aspx?sessionID=tjfxz255rcn0ei55nskjfl55&originalURL=http%3a +%2f%2fwww.everydaylife.amdigital.co.uk%2findex.aspx&cookiesTesting=tr +ue HTTP/1.1 Host: secure.amdigital.co.uk User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1 +1) Gecko/20071127 Firefox/2.0.0.11 Accept: image/png,*/*;q=0.5 Accept-Language: en-us,en;q=0.5 Accept-Encoding: gzip,deflate Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 Keep-Alive: 300 Connection: keep-alive Referer: http://secure.amdigital.co.uk/Login.aspx?sessionID=tjfxz255rc +n0ei55nskjfl55&originalURL=http%3a%2f%2fwww.everydaylife.amdigital.co +.uk%2findex.aspx&cookiesTesting=true Cookie: ASP.NET_SessionId=g534qbaix4gqne551mr1gs45; AMPCAM=cam HTTP/1.x 200 OK Date: Thu, 06 Dec 2007 10:19:23 GMT Server: Microsoft-IIS/6.0 X-Powered-By: ASP.NET X-AspNet-Version: 2.0.50727 Cache-Control: private Content-Type: text/html; charset=utf-8 Content-Length: 9317 ---------------------------------------------------------- http://secure.amdigital.co.uk/Login.aspx?sessionID=tjfxz255rcn0ei55nsk +jfl55&originalURL=http%3a%2f%2fwww.everydaylife.amdigital.co.uk%2find +ex.aspx&cookiesTesting=true POST /Login.aspx?sessionID=tjfxz255rcn0ei55nskjfl55&originalURL=http%3 +a%2f%2fwww.everydaylife.amdigital.co.uk%2findex.aspx&cookiesTesting=t +rue HTTP/1.1 Host: secure.amdigital.co.uk User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1 +1) Gecko/20071127 Firefox/2.0.0.11 Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9 +,text/plain;q=0.8,image/png,*/*;q=0.5 Accept-Language: en-us,en;q=0.5 Accept-Encoding: gzip,deflate Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 Keep-Alive: 300 Connection: keep-alive Referer: http://secure.amdigital.co.uk/Login.aspx?sessionID=tjfxz255rc +n0ei55nskjfl55&originalURL=http%3a%2f%2fwww.everydaylife.amdigital.co +.uk%2findex.aspx&cookiesTesting=true Cookie: ASP.NET_SessionId=g534qbaix4gqne551mr1gs45; AMPCAM=cam Content-Type: application/x-www-form-urlencoded Content-Length: 433 __EVENTTARGET=&__EVENTARGUMENT=&__VIEWSTATE=%2FwEPDwUKLTIxOTM1NjQ3Nw9k +FgICAQ9kFgICAw8PFgIeC05hdmlnYXRlVXJsBWRodHRwOi8vYXV0aC5hdGhlbnNhbXMub +mV0Lz9hdGhfcmV0dXJsPWh0dHAlM2ElMmYlMmZzZWN1cmUuYW1kaWdpdGFsLmNvLnVrJT +JmbG9naW4uYXNweCZhdGhfZHNwaWQ9QU1QZGRk2Bb6XOr65gVrMfaRFicTepH4QYQ%3D& +UserNameTextBox=EXLIBRIS&PasswordTextbox=EXLIBRIS&LoginButton=Login&_ +_EVENTVALIDATION=%2FwEWBALbmLD7DgLw2N3fDgKi9%2FChAwL%2BjNCfD2F8eUswa7 +S9vprVTL2rvpalIrUP HTTP/1.x 302 Found Date: Thu, 06 Dec 2007 10:20:46 GMT Server: Microsoft-IIS/6.0 X-Powered-By: ASP.NET X-AspNet-Version: 2.0.50727 Location: http://www.everydaylife.amdigital.co.uk/index.aspx?sessionID +=tjfxz255rcn0ei55nskjfl55&sessionENC=Nfb%2ftuRFpS6Xd2N0ylolleZ4z9Zqn6 +SFYF%2bk6Pa0fMZY4Q31JvifZEq5BtD6f6ZqBbDptegoCj2HtkI7vWpMtmN6DGQSBfWsI +QsWDVI8KQI%3d&originalURL=http%3a%2f%2fwww.everydaylife.amdigital.co. +uk%2findex.aspx Set-Cookie: secure.root=AC78A146FA8D23827CAA1445F0CE905249CBBD1FAF0495 +65BFCAE6EB1E88592E7CAAB601986702A994CE27AB24B63F8A0F4C236BBB21CE353D3 +7675F217FA4E6543DA341A37DD6042B85E5A1F3A5FE12A4A3A3E9DE0020BB6F81795D +D1F61EBA5558E5711205BC5C32C705D12DE93006; path=/; HttpOnly Set-Cookie: camlogintoken=8f90be72-817c-4679-aefd-7542fa6e808b; domain +=.amdigital.co.uk; expires=Thu, 06-Dec-2007 10:21:36 GMT; path=/ Cache-Control: private Content-Type: text/html; charset=utf-8 Content-Length: 407 ---------------------------------------------------------- http://www.everydaylife.amdigital.co.uk/index.aspx?sessionID=tjfxz255r +cn0ei55nskjfl55&sessionENC=Nfb%2ftuRFpS6Xd2N0ylolleZ4z9Zqn6SFYF%2bk6P +a0fMZY4Q31JvifZEq5BtD6f6ZqBbDptegoCj2HtkI7vWpMtmN6DGQSBfWsIQsWDVI8KQI +%3d&originalURL=http%3a%2f%2fwww.everydaylife.amdigital.co.uk%2findex +.aspx GET /index.aspx?sessionID=tjfxz255rcn0ei55nskjfl55&sessionENC=Nfb%2ftu +RFpS6Xd2N0ylolleZ4z9Zqn6SFYF%2bk6Pa0fMZY4Q31JvifZEq5BtD6f6ZqBbDptegoC +j2HtkI7vWpMtmN6DGQSBfWsIQsWDVI8KQI%3d&originalURL=http%3a%2f%2fwww.ev +erydaylife.amdigital.co.uk%2findex.aspx HTTP/1.1 Host: www.everydaylife.amdigital.co.uk User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1 +1) Gecko/20071127 Firefox/2.0.0.11 Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9 +,text/plain;q=0.8,image/png,*/*;q=0.5 Accept-Language: en-us,en;q=0.5 Accept-Encoding: gzip,deflate Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 Keep-Alive: 300 Connection: keep-alive Referer: http://secure.amdigital.co.uk/Login.aspx?sessionID=tjfxz255rc +n0ei55nskjfl55&originalURL=http%3a%2f%2fwww.everydaylife.amdigital.co +.uk%2findex.aspx&cookiesTesting=true Cookie: ASP.NET_SessionId=tjfxz255rcn0ei55nskjfl55; camlogintoken=8f90 +be72-817c-4679-aefd-7542fa6e808b HTTP/1.x 302 Found Date: Thu, 06 Dec 2007 10:20:46 GMT Server: Microsoft-IIS/6.0 X-Powered-By: ASP.NET X-AspNet-Version: 1.1.4322 Location: /login.aspx?ReturnUrl=%2findex.aspx%3fsessionID%3dtjfxz255rc +n0ei55nskjfl55%26sessionENC%3dNfb%252ftuRFpS6Xd2N0ylolleZ4z9Zqn6SFYF% +252bk6Pa0fMZY4Q31JvifZEq5BtD6f6ZqBbDptegoCj2HtkI7vWpMtmN6DGQSBfWsIQsW +DVI8KQI%253d%26originalURL%3dhttp%253a%252f%252fwww.everydaylife.amdi +gital.co.uk%252findex.aspx&sessionID=tjfxz255rcn0ei55nskjfl55&session +ENC=Nfb%2ftuRFpS6Xd2N0ylolleZ4z9Zqn6SFYF%2bk6Pa0fMZY4Q31JvifZEq5BtD6f +6ZqBbDptegoCj2HtkI7vWpMtmN6DGQSBfWsIQsWDVI8KQI%3d&originalURL=http%3a +%2f%2fwww.everydaylife.amdigital.co.uk%2findex.aspx Cache-Control: private Content-Type: text/html; charset=utf-8 Content-Length: 654 ---------------------------------------------------------- http://www.everydaylife.amdigital.co.uk/login.aspx?ReturnUrl=%2findex. +aspx%3fsessionID%3dtjfxz255rcn0ei55nskjfl55%26sessionENC%3dNfb%252ftu +RFpS6Xd2N0ylolleZ4z9Zqn6SFYF%252bk6Pa0fMZY4Q31JvifZEq5BtD6f6ZqBbDpteg +oCj2HtkI7vWpMtmN6DGQSBfWsIQsWDVI8KQI%253d%26originalURL%3dhttp%253a%2 +52f%252fwww.everydaylife.amdigital.co.uk%252findex.aspx&sessionID=tjf +xz255rcn0ei55nskjfl55&sessionENC=Nfb%2ftuRFpS6Xd2N0ylolleZ4z9Zqn6SFYF +%2bk6Pa0fMZY4Q31JvifZEq5BtD6f6ZqBbDptegoCj2HtkI7vWpMtmN6DGQSBfWsIQsWD +VI8KQI%3d&originalURL=http%3a%2f%2fwww.everydaylife.amdigital.co.uk%2 +findex.aspx GET /login.aspx?ReturnUrl=%2findex.aspx%3fsessionID%3dtjfxz255rcn0ei55 +nskjfl55%26sessionENC%3dNfb%252ftuRFpS6Xd2N0ylolleZ4z9Zqn6SFYF%252bk6 +Pa0fMZY4Q31JvifZEq5BtD6f6ZqBbDptegoCj2HtkI7vWpMtmN6DGQSBfWsIQsWDVI8KQ +I%253d%26originalURL%3dhttp%253a%252f%252fwww.everydaylife.amdigital. +co.uk%252findex.aspx&sessionID=tjfxz255rcn0ei55nskjfl55&sessionENC=Nf +b%2ftuRFpS6Xd2N0ylolleZ4z9Zqn6SFYF%2bk6Pa0fMZY4Q31JvifZEq5BtD6f6ZqBbD +ptegoCj2HtkI7vWpMtmN6DGQSBfWsIQsWDVI8KQI%3d&originalURL=http%3a%2f%2f +www.everydaylife.amdigital.co.uk%2findex.aspx HTTP/1.1 Host: www.everydaylife.amdigital.co.uk User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1 +1) Gecko/20071127 Firefox/2.0.0.11 Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9 +,text/plain;q=0.8,image/png,*/*;q=0.5 Accept-Language: en-us,en;q=0.5 Accept-Encoding: gzip,deflate Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 Keep-Alive: 300 Connection: keep-alive Referer: http://secure.amdigital.co.uk/Login.aspx?sessionID=tjfxz255rc +n0ei55nskjfl55&originalURL=http%3a%2f%2fwww.everydaylife.amdigital.co +.uk%2findex.aspx&cookiesTesting=true Cookie: ASP.NET_SessionId=tjfxz255rcn0ei55nskjfl55; camlogintoken=8f90 +be72-817c-4679-aefd-7542fa6e808b HTTP/1.x 302 Found Date: Thu, 06 Dec 2007 10:20:46 GMT Server: Microsoft-IIS/6.0 X-Powered-By: ASP.NET X-AspNet-Version: 1.1.4322 Location: http://www.everydaylife.amdigital.co.uk/index.aspx Set-Cookie: Login=83BB09A8C256DEB5FA12F7B0BCCFF564017D18E83D4A5F4F9905 +A70981B4B513350D92164ABA56340F9AEDB0B6438A36E6FE926C35A522980CB2FBA33 +2D185494C120C81251F6B4698F6D8101747267BA9CFB143A5EB12527DB4DE1FF9857A +27D6C4341D0981F92F644A3F8E6FC0E422CB4294066D10B0C2400209719FA5B1D9; p +ath=/ Cache-Control: private Content-Type: text/html; charset=utf-8 Content-Length: 167 ---------------------------------------------------------- http://www.everydaylife.amdigital.co.uk/index.aspx GET /index.aspx HTTP/1.1 Host: www.everydaylife.amdigital.co.uk User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1 +1) Gecko/20071127 Firefox/2.0.0.11 Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9 +,text/plain;q=0.8,image/png,*/*;q=0.5 Accept-Language: en-us,en;q=0.5 Accept-Encoding: gzip,deflate Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 Keep-Alive: 300 Connection: keep-alive Referer: http://secure.amdigital.co.uk/Login.aspx?sessionID=tjfxz255rc +n0ei55nskjfl55&originalURL=http%3a%2f%2fwww.everydaylife.amdigital.co +.uk%2findex.aspx&cookiesTesting=true Cookie: ASP.NET_SessionId=tjfxz255rcn0ei55nskjfl55; camlogintoken=8f90 +be72-817c-4679-aefd-7542fa6e808b; Login=83BB09A8C256DEB5FA12F7B0BCCFF +564017D18E83D4A5F4F9905A70981B4B513350D92164ABA56340F9AEDB0B6438A36E6 +FE926C35A522980CB2FBA332D185494C120C81251F6B4698F6D8101747267BA9CFB14 +3A5EB12527DB4DE1FF9857A27D6C4341D0981F92F644A3F8E6FC0E422CB4294066D10 +B0C2400209719FA5B1D9 HTTP/1.x 200 OK Date: Thu, 06 Dec 2007 10:20:46 GMT Server: Microsoft-IIS/6.0 X-Powered-By: ASP.NET X-AspNet-Version: 1.1.4322 Cache-Control: private Content-Type: text/html; charset=utf-8 Content-Length: 9611 ----------------------------------------------------------
#!/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' authentic +ation if($response =~ /action="Login.aspx\?sessionID=(.*?)&originalU +RL=/){ $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?ses +sionID=$session&originalURL=http%3a%2f%2fwww.everydaylife.amdigital.c +o.uk%2findex.aspx"; ##The POST content my $content = "__EVENTTARGET=&__EVENTARGUMENT=&__VIEWSTATE=$view_s +tate&UserNameTextBox=EXLIBRIS&PasswordTextbox=EXLIBRIS&LoginButton=Lo +gin&__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 N +T 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";
Edit: g0n - readmore tags
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Problem with cookies
by moritz (Cardinal) on Dec 06, 2007 at 13:19 UTC | |
by Anonymous Monk on Dec 06, 2007 at 13:26 UTC | |
by chrism01 (Friar) on Dec 07, 2007 at 01:08 UTC |