bobdole has asked for the wisdom of the Perl Monks concerning the following question:

I am having a little issue with a script that logs onto a site that uses cookies.

When I run through it with a regular browser it looks like the cookies are being set with javascript after you log in

document.cookie="SiteUser=asfasfasfsf23233;

And when I watch the headers via Live HTTP headers I can see

Cookie: SiteUser=asfasfasfsf23233;

being passed but when I try to log in with my script I get a "You must allow cookies" error after I log in.

Is there a way I can take that "SiteUser=asfasfasfsf23233;" out of the javascript and manually send it with my headers?

Replies are listed 'Best First'.
Re: Mechanize and cookies
by ForgotPasswordAgain (Vicar) on Dec 11, 2007 at 18:04 UTC
      Thanks I will take a look at that.

      I actually just used
      $mech->add_header( 'Cookie' => '...')
      and manually put in the value from my browser session and it worked fine in my script when I made a get call, so I think I will just parse out the cookie from the javascript and manually set it when I make calls to any of the pages on the site.
Re: Mechanize and cookies
by olus (Curate) on Dec 11, 2007 at 18:12 UTC
    You could try sending the Cookie header with HTTP::Request::Common
    use HTTP::Request::Common qw(GET); use LWP::UserAgent; my $ua = new LWP::UserAgent; my $res = $ua->request( GET 'url', Cookie => 'SiteUser=asfasfasfsf23233', );