awohld has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl -w use strict; use LWP; my $site0 = "http://mysite.com/ my $site = "https://login.mysite.com/dir/auth"; my @netscape_headers = ( # Set headers to look like Netscape 'User-Agent' => 'Mozilla/4.76 [en] (Win98; U)', 'Accept-Language' => 'en-US', 'Accept-Charset' => 'iso-8859-1,*,utf-8', 'Accept-Encoding'=> 'gzip', 'Accept' => "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, +image/png, */*", ); my $browser = LWP::UserAgent->new(); # Create virtual browser $browser->cookie_jar( {} ); # Enable cookies my $response = $browser->get($site0, @netscape_headers); die "Error: ", $response->status_line unless $response->is_success; my $response = $browser->post( $site, [ "pRedirect" => "", "fRedirect" => "", "SafeWordUser" => "username" ] ); die "Error: ", $response->status_line unless $response->is_success; print $response->content(); $response = $browser->post( $site, [ "pRedirect" => "", "fRedirect" => "", "SafeWordPassword" => "password" ] ); die "Error: ", $response->status_line unless $response->is_success; print $response->content();
#!/usr/bin/perl -w use strict; use LWP; my $site = "https://login.mysite.com/dir/auth"; my $site1 = "https://www.mysite.com/protected/dir/main.htm"; my @netscape_headers = ( # Set headers to look like Netscape 'User-Agent' => 'Mozilla/4.76 [en] (Win98; U)', 'Accept-Language' => 'en-US', 'Accept-Charset' => 'iso-8859-1,*,utf-8', 'Accept-Encoding'=> 'gzip', 'Accept' => "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, +image/png, */*", ); my $browser = LWP::UserAgent->new(); # Create virtual browser $browser->cookie_jar( {} ); # Enable cookies my $response = $browser->post( $site, [ "pRedirect" => "", "fRedirect" => "", "User" => "username" ],@netscape_headers ); die "Error: ", $response->status_line unless $response->is_success; $response = $browser->post( $site, [ "pRedirect" => "", "fRedirect" => "", "Password" => "password" ],@netscape_headers ); $response = $browser->get($site1, @netscape_headers); print $response->content();
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Automatically Logging in to a Webpage
by Vinzzz (Initiate) on May 24, 2005 at 09:12 UTC | |
by awohld (Hermit) on May 24, 2005 at 16:32 UTC | |
|
Re: Automatically Logging in to a Webpage
by Anonymous Monk on May 24, 2005 at 09:36 UTC | |
|
Re: Automatically Logging in to a Webpage
by Anonymous Monk on May 24, 2005 at 09:32 UTC | |
by awohld (Hermit) on May 24, 2005 at 13:53 UTC | |
by Fletch (Bishop) on May 24, 2005 at 17:44 UTC |