Vanquish has asked for the wisdom of the Perl Monks concerning the following question:
#!/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 coo +kie store object $cookie_jar->add_cookie_header($request); $ua->cookie_jar( $cookie_jar ); # Associate co +okie store with the user agent my $header = HTTP::Headers->new( Content_Type => 'text/html' +, # Create an HTTP headers object User_Agent => 'Release_Bu +ild/1.0' ); $header->as_string; my $request = HTTP::Request::Common::POST( 'http://10.1.19.22', $l +ogin, User_Agent => 'Relea +se_Build/1.0' ); $request->as_string; my $response = $ua->request( $request ); # Send IITS lo +gin 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; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: webpage login
by davis (Vicar) on Jun 29, 2004 at 10:33 UTC | |
|
Re: webpage login
by gellyfish (Monsignor) on Jun 29, 2004 at 09:02 UTC |