Solved

Can't figure out how to set a cookie

Posted on 2013-06-04
5
336 Views
Last Modified: 2013-06-10
I'm doing something wrong here, but I can't see what it is.  I'm trying to set a cookie value in the cookie_jar but nothing happens:

I'm sure it's a syntax error...

Here is the code:
        use LWP;
        use HTTP::COOKIES;
         my($browser) = LWP::UserAgent->new;
        $browser->cookie_jar(HTTP::Cookies->new());
        $browser->cookie_jar->set_cookie   ('1','ASP.NET_SessionId',$GLASP_NET_SessionId,"/","","",1,1,900,0);

When I run Dumper on the $browser the cookie jar is always empty.

$VAR1 = bless( {
                 'COOKIES' => {}
               }, 'HTTP::Cookies' );
0
Comment
Question by:geekdad1
  • 3
  • 2
5 Comments
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 39220686
This page makes it look like you have things out of order.

http://search.cpan.org/~gaas/HTTP-Cookies-6.01/lib/HTTP/Cookies.pm
0
 
LVL 1

Author Comment

by:geekdad1
ID: 39222902
I've been through that page and others with no luck.  Not sure what you mean by out of order.  You have to set up a user agent first.  You have to have a cookie jar in order to use the set-cookie method.  What could possibly be out of order?

If you have an example that works, it would go a long way to helping me out here.
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 39223225
According to that page I linked, you have to set up the cookie jar first before you can assign anything to it.
0
 
LVL 1

Accepted Solution

by:
geekdad1 earned 0 total points
ID: 39223802
OK:

This code also doesn't work.

       use LWP;
        use HTTP::COOKIES;
         my($browser) = LWP::UserAgent->new;
        $cjar =HTTP::Cookies->new();
        $cjar->cookie_jar->set_cookie   ('1','ASP.NET_SessionId',$GLASP_NET_SessionId,"/","","",1,1,900,0);

I ran cpan to do an upgrade but it said I had the most recent version.  For some reason my system has several copies of Cookies.pm in various locations.  I got rid of all but the latest to make sure there wasn't any compatibility problems.

Not to worry, I figured it out by debugging the Cookies.pm code.  Turns out that if you don't include a value for port, it gives up and returns a blank cookie jar.  Maybe someone could update the documentation to point out what the mandatory fields are.
0
 
LVL 1

Author Closing Comment

by:geekdad1
ID: 39234124
The helper pointed me to documentation that I had already read and re-reading it wasn't much help.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SIMPLE Perl Regex 1 162
instmodsh - listing perl modules 2 83
Put query string from URL request -  PERL HTTP Daemon 2 83
parse a file and get data out 11 77
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question