We used to pull info from a partner's web site using LWP. They used form based authentication and cookies. The code below (with a different url) worked until they changed to using Tomcat.
Now after trying to log in and request the secured page, I get a 302 error (moved). If I try to pull the secured page a second time I just get the login form. I'm guessing that the login_servlet dispatches to secure.jsp and maybe that's causing my problem (302). However, I tried logging in via my browser with cookies turned off, and I was still able to log in, so maybe it has something to do with the sessioning? This site doesn't use ssl by the way. Am I missing something? Thanks.... -- #!/usr/bin/perl -w use strict; use LWP::UserAgent; use HTTP::Status; use HTTP::Cookies; use HTTP::Request::Common; $|++; ### Config ### my $login = 'http://www.someserver.com/login_servlet'; # Create new UserAgent object (browser) my $ua = LWP::UserAgent->new(); # Setup cookie jar $ua->cookie_jar(HTTP::Cookies->new(file=> 'cookie_jar', autosave => 1)); # Give the browser a name $ua->agent("Mozilla/4.7"); # Set the timeout value - only wait 60 seconds. $ua->timeout(60); ### Login ### my $request = $ua->simple_request(POST $login, { username => 'my_username', password => 'my_password', }); # url of page we need to get once logged in my $url = 'http://www.someserver.com/secure.jsp'; # NOTE: This one gives a 302 (moved) $request = HTTP::Request->new(GET => $url); my $response = $ua->request($request); if($response->is_success) { print $response->content; } else { print "Error getting document: ", $response->status_line, "\n"; } # NOTE: This pulls html for login form :( $request = HTTP::Request->new(GET => $url); $response = $ua->request($request); if($response->is_success) { print $response->content; } else { print "Error getting document: ", $response->status_line, "\n"; } __________________________________________________ Do You Yahoo!? Yahoo! - Official partner of 2002 FIFA World Cup http://fifaworldcup.yahoo.com
