in reply to multiple cookies in LWP HTTP:Cookies

Looking at HTTP::Cookies, I find the following comment:

# A HTTP::Cookies object is a hash. The main attribute is the # COOKIES 3 level hash: $self->{COOKIES}{$domain}{$path}{$key}.

So, either your separate cookie lines have all the same domain+path+key, or you're not putting them correctly or reading them correctly. So - what is the code you're using to read/store/retrieve the cookies? What is the cookie data you're using?

Replies are listed 'Best First'.
Re^2: multiple cookies in LWP HTTP:Cookies
by RinaR (Initiate) on Jan 14, 2009 at 13:06 UTC
    This is in answer to the replies by Corion and Anonymous.
    In many sites I can see multiple cookies, and this problem only happens at a few sites.
    ###part of the code picked out of a long module ####
    ###this code is here to be read, but not run ####
    sub call_httpd_exec{ use LWP::UserAgent; use HTTP::Cookies; my $user_agent = LWP::UserAgent->new; ###cookie handling $user_agent->cookie_jar(HTTP::Cookies->new()); $cookie_list = $hash->{cookies}; my $path; my $cookie; my $cookie_url_obj = URI->new($hash->{url}); foreach $cookie (split(/;/,$cookie_list)) { $path=""; my ($key,$value); if ($cookie =~ /=/){ $key = $`; $value = $'; } $user_agent->cookie_jar->set_cookie(0,$key,$value,"/$path" +,$cookie_url_obj->host); } $reqObj = new HTTP::Request($method,$urlObj,$hdrObj,$cgi_param); $resObj = $user_agent->request($reqObj); my $cookies_new = $user_agent->cookie_jar->as_string; }
    ### part of $reqObj containing 'cookie' (taken from debugging)
    '_headers' => HTTP::Headers=HASH(0xa313f2c) 'accept' => 'application/pdf, image/gif, image/x-xbitmap, ima +ge/jpeg, image/pjpeg, application/vnd.ms-powerpoint, application/vnd. +ms-excel, application/msword, */*' 'accept-language' => 'en-us' 'cache-control' => 'no-cache' 'connection' => 'Keep-Alive' 'cookie' => 'Safari=cookieversion=2&portal=proquest&key=28C4E +E2EC2EFBDF1267FF592AAD06A5BAE28C372EF649FA2330F854B8672810B0063D8E5A8 +E98CB62C04AE2C7B9BA3CF148D6991A177D401FB48505D6F8A7A89C89BA42D8CF6F79 +7869A9946885022A0F3066521D43FAC3E1AAFCA769B525590&sessionid=5b172b6b- +092a-48a4-8b84-81ee5f1892e6&ref=Undefined&oref=%2f' 'cookie2' => '$Version="1"' 'soapaction' => ' ' 'user-agent' => 'Mozilla/4.0 (compatible; MSIE 5.01; Windows +NT 5.0)' '_method' => 'GET' '_protocol' => undef
    ### the cookie as it appears in firefox
    Cookie: s_cc=true; s_sq=%5B%5BB%5D%5D; Safari=cookieversion=2&portal=p +roquestcombo&key=64557762631998E5DD4D23ABF32D1C0FCEAA96D75669DF33AEFC +D5004C989B6082ACAEDCFD96951AE809EBAFFDFBED8048F28F2E9B20EC2F22865FC07 +FAD7F31B7916ECFF69E6EBB6AA5C07F7C74E346A506E0F1C58BD71AB7ECEE419D1739 +E4EA308D&sessionid=f2281fc8-facd-4ea6-ab1e-68daacfcbceb&ref=Undefined +&logged=true&oref=%2f; State=aph=PZURKFXQXnYHVSNRRMPjVILBBZANIEHFVCNf +oZGYRXVVCLASVDKBWKHATBMV&rememberpassword=&uicode=proquest&PromoCode= +&itemsperpage=20&portal=proquestcombo

      So it seems that there is only one cookie stored. But you don't show us the values and paths and domains of the cookies sent. It helps us to help you better when we see what data is sent from the webserver to your client, especially the Set-Cookie: headers. You can obtain that data for example by using a network sniffer like Wireshark or via a carefully crafted telnet session to the host in question.

        Sorry, I didnt write it clearly
        I will write out the cookies again with the cookie name in bold and the value after =
        there are 4 cookies
        Cookie:
        s_cc=true;
        s_sq=%5B%5BB%5D%5D;
        Safari=cookieversion=2&portal=p +roquestcombo&key=64557762631998E5DD4D23ABF32D1C0FCEAA96D75669DF33AEFC +D5004C989B6082ACAEDCFD96951AE809EBAFFDFBED8048F28F2E9B20EC2F22865FC07 +FAD7F31B7916ECFF69E6EBB6AA5C07F7C74E346A506E0F1C58BD71AB7ECEE419D1739 +E4EA308D&sessionid=f2281fc8-facd-4ea6-ab1e-68daacfcbceb&ref=Undefined +&logged=true&oref=%2f;
        State=aph=PZURKFXQXnYHVSNRRMPjVILBBZANIEHFVCNf +oZGYRXVVCLASVDKBWKHATBMV&rememberpassword=&uicode=proquest&PromoCode= +&itemsperpage=20&portal=proquestcombo

        but only the cookie named 'Safari' gets to my program