Cookies

Discussion in 'Perl Misc' started by Tuba Chuck, Nov 16, 2004.

  1. Tuba Chuck

    Tuba Chuck Guest

    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;
     
    Tuba Chuck, Nov 16, 2004
    #1
    1. Advertising

  2. Tuba Chuck <> wrote:

    > 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.


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Nov 16, 2004
    #2
    1. Advertising

  3. Tuba Chuck

    Tuba Chuck Guest

    Tad McClellan <> wrote in message news:<>...
    > Tuba Chuck <> wrote:
    >
    > > 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!
     
    Tuba Chuck, Nov 16, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alex Nitulescu

    Response.Cookies vs Request.Cookies

    Alex Nitulescu, Feb 3, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    8,580
    Hans Kesting
    Feb 3, 2005
  2. Andy Fish
    Replies:
    3
    Views:
    6,582
    Fredrik Lindner
    Nov 6, 2003
  3. user
    Replies:
    3
    Views:
    687
    =?ISO-8859-1?Q?G=F6ran_Andersson?=
    Mar 31, 2007
  4. archana
    Replies:
    1
    Views:
    526
  5. _Who
    Replies:
    7
    Views:
    2,752
Loading...

Share This Page