Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Embedding cookies in HTTP requests

by Torgo (Beadle)
on May 07, 2002 at 17:52 UTC ( #164755=perlquestion: print w/replies, xml ) Need Help??

Torgo has asked for the wisdom of the Perl Monks concerning the following question:

Hello monks..

I need to write a little command line script to stress-test a CGI script here at work. I'm very familiar with LWP and HTTP::Request, but this particular CGI needs a username and password checksum sent along with each request in a cookie. I've looked for examples of how to embed cookies inside of HTTP requests, but the ones I've found are incomplete and/or incredibly complicated. Is there a simple way to do this?
--
I write the code while the master is away!

Edit kudra, 2002-05-07 Added 'HTTP' to title per ntc req

Replies are listed 'Best First'.
Re: Embedding cookies in requests
by Fletch (Bishop) on May 07, 2002 at 17:57 UTC
    $ perldoc lwpcook [...] COOKIES Some sites like to play games with cookies. By default LWP ignores cookies provided by the servers it visits. LWP will collect cookies and respond to cookie requests if you set up a cookie jar. use LWP::UserAgent; use HTTP::Cookies; $ua = LWP::UserAgent->new; $ua->cookie_jar(HTTP::Cookies->new(file => "lwpcookies.txt", autosave => 1)); # and then send requests just as you used to do $res = $ua->request(HTTP::Request->new(GET => "http://www.yah +oo.no")); print $res->status_line, "\n"; [...]

    Looks rather complete and simple to me. HTTP::Cookies is also well documented.

    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: Embedding cookies in requests
by wardk (Deacon) on May 07, 2002 at 19:26 UTC
    Take a look at LWP::UserAgent:
    $ua->cookie_jar([$cookie_jar_obj]) Get/set the cookie jar object to use. The only requirement is that the cookie jar object must implement the extract_cookies($request) and add_cookie_header($response) methods. These methods will then be invoked by the user agent as requests are sent and responses are received. Normally this will be a "HTTP::Cookies" object or some subclass. The default is to have no cookie_jar, i.e. never automatically add "Cookie" headers to the requests.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://164755]
Approved by DaWolf
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2022-05-24 01:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (82 votes). Check out past polls.

    Notices?