Cookies

T

Tuba Chuck

Im trying to make a script that will login to my Pitas blog and then
post an entry. I seem to be having problems with the cookies. The
script is:
#!/usr/bin/perl
use HTTP::Request::Common qw(POST);
use LWP::UserAgent;
use HTTP::Cookies;

#Get needed info
print 'Login: ';
$uname = <STDIN>;
print 'Password: ';
$pass = <STDIN>;
print 'Date: ';
$date = <STDIN>;
print 'Time: ';
$time = <STDIN>;
print 'Title: ';
$pagename = <STDIN>;
print 'Entry: ';
$entry = <STDIN>;

$cookie_jar = HTTP::Cookies->new();

$login = LWP::UserAgent->new();
my $reql = POST 'http://www.pitas.com/cgi-bin/login.phtml', [
'username' => $uname, 'password' => $pass, 'remember_me' => 'no' ];
$responsel = $login->request($reql);

$addent = LWP::UserAgent->new();
my $requ = POST 'http://www.pitas.com/cgi-bin/update.phtml', [ 'date'
=> $date, 'time' => $time, 'url' => '#', 'pagename' => $pagename,
'entry' => $entry ];
$cookie_jar->add_cookie_header($requ);
$cookie_jar->extract_cookies($responsel);
$addent->request($requ);

exit;
 
T

Tad McClellan

Tuba Chuck said:
I seem to be having problems with the cookies.
script is:
#!/usr/bin/perl

use warnings;
use strict;

Ask for all the help you can get!

$cookie_jar = HTTP::Cookies->new();

$login = LWP::UserAgent->new();


$login->cookie_jar($cookie_jar);

You never associated that cookie jar with the user agent.

my $reql = POST 'http://www.pitas.com/cgi-bin/login.phtml', [
'username' => $uname, 'password' => $pass, 'remember_me' => 'no' ];
$responsel = $login->request($reql);
$addent = LWP::UserAgent->new();


Why do you need another UserAgent?

Just reuse $login.
 
T

Tuba Chuck

Tad McClellan said:
Tuba Chuck said:
I seem to be having problems with the cookies.
script is:
#!/usr/bin/perl

use warnings;
use strict;

Ask for all the help you can get!

$cookie_jar = HTTP::Cookies->new();

$login = LWP::UserAgent->new();


$login->cookie_jar($cookie_jar);

You never associated that cookie jar with the user agent.

my $reql = POST 'http://www.pitas.com/cgi-bin/login.phtml', [
'username' => $uname, 'password' => $pass, 'remember_me' => 'no' ];
$responsel = $login->request($reql);
$addent = LWP::UserAgent->new();


Why do you need another UserAgent?

Just reuse $login.

Thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top