Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^3: Missing cookies with LWP::UserAgent and HTTP::Cookies

by borisz (Canon)
on Apr 12, 2006 at 18:54 UTC ( [id://542923]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Missing cookies with LWP::UserAgent and HTTP::Cookies
in thread Missing cookies with LWP::UserAgent and HTTP::Cookies

Then the server did not send a cookie! Here is a complete TESTED working example, that prints a cookie.
use LWP::UserAgent; use HTTP::Cookies; my $cjar = HTTP::Cookies->new(); my $ua = LWP::UserAgent->new( keep_alive => '1', ); $ua->cookie_jar($cjar); my $req = HTTP::Request->new( GET => 'http://derstandard.at/' ); my $response = $ua->request($req); print $cjar->as_string;
Boris

Replies are listed 'Best First'.
Re^4: Missing cookies with LWP::UserAgent and HTTP::Cookies
by neilwatson (Priest) on Apr 12, 2006 at 18:58 UTC
    This is interesting. I tested with several URLs and yes, it appears that the server did not send a cookie. However, if I visit the same URL with Firefox I receive a cookie. Does this mean that there is a server side mechanism that may not send cookies to all agents?

    Neil Watson
    watson-wilson.ca

      Thats not uncommon. You can fake your useragent with $ua->agent('blabla'); or with my $ua = LWP::UserAgent->new( keep_alive => '1', agent => 'Mozilla/5.0'); . Try it.
      Boris
      Hey Folks, I was having this issue several years ago (about 4-5 now) where one of my systems would get a cookie from the server, and another would not. I tried everything, newer modules, older modules, different perl versions, reinstalling perl altogether; and still couldn't figure it out. It seemed once a system decided that it didn't want the cookie it wasn't going to take it. I had a contact at the server side, and checking the log files he assured me that cookies were being sent for both systems. I turned on LWP debug in verbose and saw that A cookie was recieved, but as soon as I finished the user agent request, and tried to print Dumper($cookie_jar) the jar was empty again. I gave up and ran the code on a system where it worked, and called it from the other system where I needed it. This problem just resurfaced this morning, A system that could get cookies just stopped for no apparent reason. Since this morning was so close to the DST switch, we finally suspected that it might be related to the expiration data of the cookie. It turns out that the cookies.pm module was getting the cookie, but then discarding it based on a bad timestamp on one of the systems (server or client) and the differences in DST settings. Disabling the $expires checking in the cookies.pm module allowed the saving of, and returning of the cookie. That's not the fix obviously, as it's ugly beyond compare. But I do notice that the module make some use of the $EPOCH_OFFSET environment variable and also has provisions for MacOS's different EPOCH date. Perhaps, any reference to the epoch might best be left for things far more permanent than web cookies. -Dan.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://542923]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (8)
As of 2024-03-28 21:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found