I have a little problem with the module HTML::Form. I connect first by an http address that requires a login and password. I get the form and return it completed.
Following this, the server sends me that the page I specified in the url ($base). But this page, recovered in the variable $res2, is in fact a form that I'd like to complete my script. So I write this line: my $form2 = HTML::Form -> parse ($res2 -> content), but the shell gives me the following error: HTML::Form:: parse: No $base_url provided at scriptHttp2qua.pl line 39
I know it must normally specify the url, but it is useless in this case. If I specify the url, I have the following error: Can not call method "value" on an undefined value at scriptHttp2qua.pl line 40.
Does someone can help me get the second form in $res2 (which includes the header + form)?
In addition, cookies can not be erased at the end of my script. Does anybody know why? Should we close the connection properly?
Here's the code so you can see what I want to do:
PHP Code:
#!/usr/bin/perl -w
use strict;
use LWP::UserAgent;
use HTML::Form;
use HTTP::Cookies;
use LWP::Simple;
# personal settings
my ($user, $pass ) = qw(name password);
my $base = 'http://X.X.X.X/RTIR/Create.html?Queue=Incidents';
my $req;
my $cookies = 'cookies.txt';
#initialization of the agent
my $ua = LWP::UserAgent->new(agent => 'Mozilla/5.0 (X11; U; Linux i686; fr; rv:1.9.0.14)',
cookie_jar => HTTP::Cookies->new(
file => $cookies,
autosave => 1,
ignore_discard => 1 )
);
# creation of the request
$req = HTTP::Request->new( GET => "$base" );
# executes the query and receives the response
my $res = $ua->request($req);
die $res->status_line if not $res->is_success;
# form the login
my $form = ( HTML::Form->parse($res->content, $base));
# fills the fields
$form->find_input('user')->value($user);
$form->find_input('pass')->value($pass);
# validate and return the form
my $res2 = $ua->request( $form->click );
print $res2->content;
my $form2 = HTML::Form->parse( $res2->content );
Bookmarks