Hi,
I finally was able to get the code running for login to a site (thanks to some anonymous person's help). The way I do it is that I parse the form, populate login information and send it with cookies. I get the following error when I set the cookie.
Can't locate object method "host" via package "URI::_generic" at D:/Perl/site/lib/URI/WithBase.pm line 41.
I printed out debug statements to find out where the problem occurs which is Step 12 (after the statement (print "55\n"'). Can someone please tell me what possibly could go wrong?
use HTTP::Cookies;
use HTML::Form;
use LWP;
use URI;
require 'dumpvar.pl';
my $LOGIN = ''; # put your login name here
my $PASSWD = '';# password here
my $ua = LWP::UserAgent->new(); # Step 1
$ua->agent('Mozilla'); # habit
my $url = 'http://www.genesisreports.com/genesis/user/login.asp'; # St
+ep 2
my $login_req = HTTP::Request->new(GET => $url); # Step 2
my $login_res = $ua->request($login_req); # Step 3
my $html = $login_res->content;
my $form = HTML::Form->parse($html,'http://www.genesisreports.com/gene
+sis/user/login.asp'); # Step 4
dumpValue(\$form); # Step 5
$form->value('artist',$LOGIN); # Step 6
$form->value('albumcode',$PASSWD); # Step 6
my $req = $form->click; # Step 7
print "11\n";
my $res = $ua->request($req); # Step 8
print "22\n";
my $cookie_jar = HTTP::Cookies->new(); # Step 9
$cookie_jar->extract_cookies($res); # Step 9
print "33\n";
my $goto = $res->header('location'); # Step 10
print "44\n";
my $new_req = HTTP::Request->new(GET => $goto); # Step 11
print "55\n";
$cookie_jar->add_cookie_header($new_req); # Step 12
print "66\n";
my $new_res = $ua->request($new_req); # Step 13
print "77\n";
# All done or you could keep going.
# Parse this page for forms, URL's, or data
# and have fun:)
print $new_res->headers_as_string,"\n\n";
print $new_res->content,"\n";
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.