Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Need to Access one page after authentication in perl

by varghees (Novice)
on Jul 12, 2012 at 02:16 UTC ( #981285=perlquestion: print w/ replies, xml ) Need Help??
varghees has asked for the wisdom of the Perl Monks concerning the following question:

I tried to access the authenticated page config.cgi using the below code. But I am not able to access them with the authenticated session. I get only the login page at the second request. Somebody please tell me whats wrong in this script.
my $ua = LWP::UserAgent->new; $ua->agent("MyApp/0.1 "); $url = 'http://localhost/web_authenticate_post.cgi'; $req = HTTP::Request->new(POST => $url); $req->content_type('application/x-www-form-urlencoded'); $req->content('username=security&password=security&login=Login'); my $res=$ua->request($req); if($res->is_success){ $res1 = $ua->request(HTTP::Request->new(GET=>'http://localhost/conf +ig.cgi' )); print $res1->content; } else{ print $res->status_line; }

Comment on Need to Access one page after authentication in perl
Download Code
Re: Need to Access one page after authentication in perl
by monsoon (Pilgrim) on Jul 12, 2012 at 02:57 UTC
    A shot in the dark as i'm not really familiar with this stuff. I thought the ampersands in the url encoded string need to be replaced with percent escape "%26". Or are the web servers forgiving about that?
Re: Need to Access one page after authentication in perl
by bulk88 (Priest) on Jul 12, 2012 at 04:58 UTC
    You need to use cookies. How is the server supposed to know you logged in otherwise? Basically set a "cookie jar", and any cookies received will wind up automatically in the cookie db. The db/cookie jar is usually not saved to the disk in most LWP programs and just stays around for the runtime life of the process.
Re: Need to Access one page after authentication in perl
by Anonymous Monk on Jul 12, 2012 at 06:44 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://981285]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (14)
As of 2014-08-27 11:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (237 votes), past polls