Solved

Can't figure out how to set a cookie

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

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.…
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…
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…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

813 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

15 Experts available now in Live!

Get 1:1 Help Now