in reply to HTTP::Cookies what am i missing? (Moved from Q&A)

OK here is the answer. I know i posted the question but someone gave m +e the answer in the silly chatbox thingy and didnt post it. The documentation of HTTP::Cookies clearly states that it doesn't hand +le Set-Cookie3 format. Although the cookies will be in the response objec +t the $cjar->extract and $cjar->save methtods won't work with that format. my thanks to tilly i believe it was who sorted out an answer. Hence this workaround: #!/usr/bin/perl use URI; use LWP::UserAgent; use HTTP::Request; use HTTP::Headers; use HTTP::Response; use HTTP::Cookies; # Create a cookie jar. Hard coding the name of the file so we can keep + track of them. #putting in a headers object incase we need it later on. $cookie_jar = HTTP::Cookies->new('cookies.txt'); $hdrs = new HTTP::Headers(); # get a url object and a request object so we can go cruseing down the + web $url = new URI::URL('http://foo.com'); $req = new HTTP::Request(GET, $url, $hdrs); #make a useragent so we can spoof the server as to what client we actu +ally are $ua = new LWP::UserAgent; $ua->agent('Mozilla/4.0 (Compatable; MSIE 5.01; Windows NT 5.0)'); # Send out the request $responce = $ua -> request($req); #save our cookies for a rainy day in cookies.txt # here is the workaround for the moment. Passing a reference to the # cookie jar to a hand rolled subrouteen. save_cookies(\$cookie_jar); # do the rest of the script as written before. if($responce->is_success) { print $responce->content; } else { print $responce->error_as_HTML; } # Write our own subrouteen for saving the cookies off. sub save_cookies() { my $cjar = ${+shift}; my $cookies = $cjar -> as_string(); my $c, $cr; $cookies =~ s/Set-Cookie3:\s//g; my @cookies = split(/\n/, $cookies); open(FILE, '>cookies.txt'); foreach $c (@cookies) { @crumbs = split(/;\s/,$c); foreach $cr (@crumbs) { print FILE $cr, "\n"; } print FILE "\n"; } } It should be possible to extend the HTTP::Cookies.pm to handle this Se +t-Cookies3 format. I'm printing up the code of Cookies.pm and taking it home this weekend + to see what i can do about that for the time being. I would like to be able to post it h +ere and get some feed back in the future.
little_mistress@mainhall.com

Replies are listed 'Best First'.
RE: Re: HTTP::Cookies what am i missing? (Moved from Q&A)
by tilly (Archbishop) on Aug 05, 2000 at 22:29 UTC
    As I recall it, you solved your own problem. I just began looking at the code in the module, telling you what I noticed, and got you doing the same.

    Not that I mind being given credit. But I feel guilty when people are left thinking I did something that I did not do. :-)