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("http://domain.com/cgi-bin/script.cgi",$form_
+data);
$html = ($response->is_success) ? $response->content : "Page not respo
+nding";
-
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 How to display code and escape characters
are good places to start.
|