Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Need to Access one page after authentication in perl

by varghees (Novice)
on Jul 12, 2012 at 02:16 UTC ( [id://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; }

Replies are listed 'Best First'.
Re: Need to Access one page after authentication in perl
by Anonymous Monk on Jul 12, 2012 at 06:44 UTC
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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
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?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (7)
As of 2024-03-28 17:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found