#!/usr/bin/perl use LWP::UserAgent; use HTTP::Cookies; use HTTP::Request::Common ; #!/usr/bin/perl use LWP::UserAgent; use HTTP::Cookies; use HTTP::Request::Common ; use HTTP::Request; use HTTP::Response; use HTTP::Headers; use HTML::Parser; use XML::Parser; my $login = { username => 'guestuser', # login form to post to IITS userPassword => 'temp', ip_address => '10.70.30.20', successURL => 'home.asp', submit => 'login', }; my $ua = LWP::UserAgent->new( keep_alive => 1 ); # timeout => 30 ); my $cookie_jar = HTTP::Cookies->new; # Create a cookie store object $cookie_jar->add_cookie_header($request); $ua->cookie_jar( $cookie_jar ); # Associate cookie store with the user agent my $header = HTTP::Headers->new( Content_Type => 'text/html', # Create an HTTP headers object User_Agent => 'Release_Build/1.0' ); $header->as_string; my $request = HTTP::Request::Common::POST( 'http://10.1.19.22', $login, User_Agent => 'Release_Build/1.0' ); $request->as_string; my $response = $ua->request( $request ); # Send IITS login print $response->as_string(); $cookie_jar->extract_cookies($response); # Save session cookie returned in the response $cookie_jar->as_string(); while ($response->is_redirect) { my $location = $response->header( "location" ); $request = HTTP::Request->new( "GET", "http://10.1.19.22/" . $location, $header ); print $request->as_string; $response = $ua->request( $request ); print $response->as_string(); } unless ($response->is_success) { print "Response status is: ", $response->status_line(); return undef; }