Louis Selvon wrote:
Hi List members:
I am writing a perl script that automatically logs in an a password protected
admin area. Once logged in I want the script to be able to fetch pages and
also be able to submit any form post/get requests within the admin area.
However it's not working. So I need some help. Here is my current problem.
From the Perl script, I was able to login with my credentials by using the
following code:
$browser = LWP::UserAgent->new( );
$browser->env_proxy( ); # if we're behind a firewall
# Login into the script
$response = $browser->post(
"$login",
[
'user' => $username,
'password' => $password,
'submit' => 'Login'
],
);
where,
$login = the url script that processes the login data that the forms submits;
$username, and $password are the credentials.
I was able to login as I passed the following line of code:
die &error_file("Error1: $response->status_line", "sub login()") unless
$response->is_success;
<snip>
I do not see the html code that I see from my browser. I just see the php
script name.
Problem 1:
How do I get the script to return the html code for the php script ?
You can only get what the server returns. If you're trying to get the source
of a CGI script, you normally can't.
Problem 2:
For the cookies that was set, how do I set the Cookie jar to use this session
for all my requests ? If I add the following line when I create the "$browser"
object, will it work:
$browser->cookie_jar( {} );
Normal way:
my $ua = LWP::UserAgent->new;
$ua->cookie_jar(HTTP::Cookies->new);
Now I actually use all the headers that was returned after login, and added
the following to fetch a page from the admin area:
$response = $browser->get($url, @headers);
die &error_file("Error2: $response->status_line", "sub login()") unless
$response->is_success;
To print the response HTML:
print $response->content;
--
,-/- __ _ _ $Bill Luebkert ICQ=162126130
(_/ / ) // // DBE Collectibles Mailto:[EMAIL PROTECTED]
/ ) /--< o // // http://dbecoll.tripod.com/ (Free site for Perl)
-/-' /___/_<_</_</_ Castle of Medieval Myth & Magic http://www.todbe.com/
_______________________________________________
Perl-Unix-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs