I apologize for posting so much lately with what seems (to me at least) basic questions, but the docs for HTTP::Request::Commons and HTTP::Cookies are not exactly clear to me.

Nonetheless, I seem to be doing what I want to do according to how others have done it, yet something is amiss. I have set up a cookie_jar and it prints out when I print it as a string, but when I do the request, it does not make it across and I get a 404. Why is the cookie not being sent as described in about 100 documents all over the web.

#!/usr/local/bin/perl -w use strict; use LWP::UserAgent; use HTTP::Cookies; use HTTP::Request::Common qw(POST GET);; use HTTP::Headers; use HTML::Parser; use URI; my $cururi; my $url; my @urls; my $sessionid; my $browser = LWP::UserAgent->new; my $email = 'xxxxxxxx'; my $password = 'xxxxxxx'; my $req; my $res; $browser->cookie_jar(HTTP::Cookies->new(file => 'cookie_jar', autosave + => 1)); my $initurl = "http://www.amazon.com/exec/obidos/flex-sign-in/ref=pd_n +fy_gw_si/"; &browserEmulation($initurl); open(CJ,"cookie_jar"); while (<CJ>) { chomp; if ($_ =~ /session-id\=\"(\d*-\d*-\d*)\"/) { $sessionid = $1; } } close(CJ); $url = "http://www.amazon.com/exec/obidos/flex-sign-in-done/$sessionid +"; $res = $browser->simple_request(POST "$url", { 'email' => $email, 'action' => 'sign-in checked', 'next-page' => 'recs/instant-recs-sign-in-standard.htm +l', 'password' => $password, 'method' => 'get', 'opt' => 'oa', 'page' => 'recs/instant-recs-register-standard.ht +ml', 'response' => 'tg/stores/static/-/goldbox/index/', }); while ($res->is_redirect) { my $u = $res->header('location') or die "missing location: ", $res +->as_string; print "redirecting to $u\n"; $res = $browser->simple_request(GET $u); } if ($res->is_success) { print $res->as_string; } else { my $cururl = $res->base->as_string; print "Error: " . $res->status_line . " $cururl\n"; print $res->as_string; } sub browserEmulation { my $starturl = shift || die "No url supplied\n"; my $baseuri = URI->new($starturl); push @urls,$starturl; my $parser = HTML::Parser->new(api_version => 3, start_h => [\&start ,"tagname, attr"]); my $page; $browser->agent("Jonzilla/666"); while( $url = shift @urls) { my $request = new HTTP::Request 'GET' => $url; my $result = $browser->request($request); # shortens Tim's correction, but he gets credit for finding the bu +g $cururi = $result->base->as_string; if ($result->is_success) { $page .= $result->as_string; $parser->parse($result->content); } else { $page .= "Error: " . $result->status_line . " URL=$url, $baseu +ri\n"; if ($result->as_string ne "") { $page .= $result->as_string; } } return $page; } sub start { my($tag,$attr) = @_; if ($tag eq 'frame' ) { my $thisuri = URI->new($attr->{src}); push @urls, $thisuri->abs($cururi); } } } sub scan_cj { if ($_[1] eq 'session-id') { $sessionid = $_[2]; } }


I admit it, I am Paco.

Edited by footpad, ~ Sun Sep 29 03:15:30 2002 (UTC) : Added <readmore> tag, per Consideration


In reply to Cookie Not Being Set by jonjacobmoon

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.