ajay.awachar has asked for the wisdom of the Perl Monks concerning the following question:
I'm trying some web automation wherein I have to login to an web application and check the contents of page which I can get after logging in. I tried to do it with LWP::UserAgent and WWW::Mechanize modules.
Using LWP::UserAgent I'm getting status code 302 Moved Temporarily and contents of the Login page instead of the Application Page which we should get after logging in. Following is the code snippet.
#!/usr/bin/perl use strict; use LWP::UserAgent; use LWP::Simple; ## set URL my $url = "http://abc.toronto.xyz.com:65342"; my $ua = LWP::UserAgent->new(); my $res = $ua->post($url, {username => 'rkadm', password => 'rkadm'} ) +; $res->content_type('text/html'); my $response = $res->decoded_content( charset => 'none' ); print "Response Type = ".$res->content_type; print "\nResponse Status ".$res->status_line; ## view print "\nResponse = ".$res->content;
Using WWW::Mechanize after form submission, I'm getting the same contents of Login page instead of application page.
#!/usr/bin/perl -w use strict; use WWW::Mechanize; my $username = "rkadm"; my $password = "rkadm"; my $login = "Login"; my $url = "http://abc.toronto.xyz.com:65342"; # login to your photobucket.com account my $mech = WWW::Mechanize->new(); $mech->get($url); $mech->submit_form( form_name => 'loginForm', fields => { username => $username, password => $password +} ); print "Response = \n ".$mech->content( format => 'text' ); if( $mech->success() ) { print "\n Successful hit.....\n"; } print "Response = \n ".$mech->content( format => 'text' );
It should have returned the contents of application page after logging in. Any idea on this. Thanks,
Ajay
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Problem with fetching contents of page after login form submission using POST: LWP::UserAgent and WWW::Mechanize
by Corion (Patriarch) on Feb 28, 2010 at 15:33 UTC | |
by ajay.awachar (Acolyte) on Mar 14, 2010 at 20:51 UTC | |
|
Re: Problem with fetching contents of page after login form submission using POST: LWP::UserAgent and WWW::Mechanize
by almut (Canon) on Feb 28, 2010 at 15:36 UTC |