I've been coding an
Everything2 client as a learning exercise. Yesterday I was coding the portion that logs the user in; it posts the appropriate form and gets the cookie from the response to use for future logins.
# build POST request
my $req = HTTP::Request->new('POST', $postURL); # $postURL is "http:/
+/everything2.org/index.pl"
$req->content_type('application/x-www-form-urlencoded');
$req->content($postData); # $postData is "op=login&username=FOO&passw
+ord=BAR" or somesuch
# get the page
my $response = $ua->request($req);
if ($response->is_success) {
# extract the cookie from the response and return the HTTP::Cookie
+s object
$loginCookieJar->extract_cookies($response);
$loginCookieJar;
} else {
die "Could not log in.\n";
}
The cookie wasn't appearing. I searched Perl Monks and found
a similar problem, but the solution was a hand-rolled cookie-stripping function, which sounded like no fun to me.
(
On that node, the author talked about "drilling down" into the HTTP::Cookies object to see if his data was there. What's this?)
I mentioned in passing on
E2 that I was busy being confused at HTTP::Cookies, and user Cow Of Doom mentioned he'd come across a bug in that package where it could get 3-part domain names (http://www.everything2.org/) but not two-part (http://everything2.org/). He'd discovered it while coding a
node tracker for E2, and it had taken him a week to figure out what was wrong.
I went back to my code, added a "www." before my domain names, ran the script, and it worked.
Is this actually a bug, or are we both missing something? If it is a bug, has anyone else run into it?
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.