Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Can't figure out how to set a cookie

Posted on 2013-06-04
5
Medium Priority
?
340 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 84

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 84

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
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…
Six Sigma Control Plans

705 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