#!/usr/bin/perl use strict; use warnings; use LWP; my $path = "Infrastruktur/Svitsjoversikt"; my $loginurl = "http://intranett.oikt.local/user/login"; my $finaluri = "/Infrastruktur/Svitsjoversikt"; my $user = "foo"; my $pass = "bar"; my $param = "Login=$user&Password=$pass&LoginButton=1&RedirectURI=$finaluri"; # Create a user agent my $ua = LWP::UserAgent->new; $ua->agent("monitorezex/1.0 "); #push @{ $ua->requests_redirectable }, 'POST'; # Make POST requests redirectable $ua->cookie_jar({ file => "cookies.txt" }); # Create a request my $req = HTTP::Request->new( POST => $loginurl ); $req->content_type('application/x-www-form-urlencoded'); $req->content( $param ); # Pass request to the user agent and get a response back my $res = $ua->request($req); # Check the outcome of the response if ($res->is_success) { print "SUCCESS!\n"; print $res->as_string; } else { print "FAILURE: " . $res->status_line . "\n"; print $res->as_string; } exit; #### HTTP/1.1 302 Found Cache-Control: no-cache, must-revalidate Connection: close Date: Fri, 09 Oct 2009 06:45:56 GMT Pragma: no-cache Location: http://intranett.oikt.local/Infrastruktur/Svitsjoversikt Location: http://intranett.oikt.local/Infrastruktur/Svitsjoversikt Server: Apache/1.3.39 (Win32) PHP/5.2.6 Content-Language: no-bokmaal Content-Type: text/html; charset=utf-8 Expires: Mon, 26 Jul 1997 05:00:00 GMT Last-Modified: Fri, 09 Oct 2009 06:45:56 GMT Client-Date: Fri, 09 Oct 2009 06:45:56 GMT Client-Peer: 10.10.8.120:80 Client-Response-Num: 1 Client-Transfer-Encoding: chunked Refresh: 0;URL=http://intranett.oikt.local/Infrastruktur/Svitsjoversikt Served-By: intranett.oikt.local Set-Cookie: eZSESSIDoikt_intranett=v8igadrdc86koc225jk55or5e2; path=/ X-Powered-By: eZ Publish #### 10.15.0.2 - - [09/Oct/2009:08:38:31 +0200] "POST /user/login HTTP/1.1" 302 246 10.15.0.2 - - [09/Oct/2009:08:38:32 +0200] "GET /Infrastruktur/Svitsjoversikt,%20http://intranett.oikt.local/Infrastruktur/Svitsjoversikt HTTP/1.1" 404 23015