Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

I'm slowly going nuts!
Either I'm making this much too difficult or, more likely, I just don't get it. I've read though the above posts and I'm still missing it.

I have a number of .cgi web-pages that use a cookie for user authentication and I sometimes want to access these via LWP (which needs to pass the cookie.)

Here's my latest, not working, version. It runs ok, but it's not passing the cookie.

use strict; use CGI; use LWP::UserAgent; use HTTP::Cookies; my $q = new CGI; my $cookie_value = $q->cookie('name'); # Get cookie from bowser my $ua = LWP::UserAgent->new; my $cookie_jar = HTTP::Cookies->new; # Pass cookie in LWP. my $version = ''; # (from CPAN) What's this? $cookie_jar -> set_cookie($version,'name',$cookie_value,"/"); $ua -> cookie_jar($cookie_jar); my $form_data = [ name => 'value', ]; my $response = $ua->post("",$form_ +data); $html = ($response->is_success) ? $response->content : "Page not respo +nding";

In reply to Re: Passing a cookie with LWP::UserAgent by nedals
in thread Passing a cookie with LWP::UserAgent by nedals

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (1)
As of 2021-06-19 06:19 GMT
Find Nodes?
    Voting Booth?
    What does the "s" stand for in "perls"? (Whence perls)

    Results (91 votes). Check out past polls.