Solved

Can't figure out how to set a cookie

Posted on 2013-06-04
5
327 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 82

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 82

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

747 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now