develooper Front page | perl.libwww | Postings from March 2001

Problem submitting a form

Thread Next
Steve Borruso
March 21, 2001 19:28
Problem submitting a form
Message ID:

Having some difficulty submitting a form and capturing the resulting
page. Getting a 404 when I try to click() the form.

So far my script will -

Log in to a remote site with my userid/pwd (with cookies and
redirection) Successfully request a page that's full of pre filled
form data.

I now need to -

1) Alter/add data to one particular text area (should be able to
    just  parse the received content, insert my data, then paste it
    back together)

2) Need to then click the Submit button on this form, that has
    my change. Don't want to handle it by specifying name/value
    pairs as the form may change in the future.

3) Once this altered form is submitted I need to catch the resulting
   page, which is another form, and click the Submit button on that

Any assistance on what I'm doing wrong on the submit or how I can
better isolate the problem is most appreciated.


Here's my script ....

use LWP::Simple ;
use HTML::TokeParser;
use LWP::UserAgent;
use HTTP::Cookies;
use HTTP::Request::Common;
use HTML::Form;


# First login with userid/pwd handling cookies and re-direction
# This all works fine ...
$CookieFile = '/mycookiefile.tx';
my $ua = LWP::UserAgent->new;
$ua->cookie_jar(HTTP::Cookies->new(file => "$CookieFile", autosave =>
my $r = $ua->simple_request(POST "",
         url => '',
         nickname => "$myuserid"',
         password => '$mypass",
while ($r->is_redirect) {
  my $u = $r->header('location') or die "missing location: ",
  print "redirecting to $u\n";
  $r = $ua->simple_request(GET $u);
# Now request the page that contains pre-filled in form data

$Form_1_Page =
' .....';
$res = $ua->request(HTTP::Request->new(GET => "$Form_1_Page"));
$html = $res->content;

# print $html ;

# Everything works fine up to this point
# Should be able to parse $html here, inserting my change into proper
text box

# Now need to submit the altered form and capture the resulting page

$form = HTML::Form->parse($html,'');
$r = $ua->simple_request($form->click());

print $r-> as_string;


Here's the latest output ...

HTTP/1.1 200 OK Date: Wed, 21 Mar 2001 23:03:51 GMT Server:
Content-Type: text/html Client-Date: Wed, 21 Mar 2001 23:07:37 GMT

Error Occurred While Processing Request

 Error Diagnostic Information

 An error has occurred.

 HTTP/1.0 404 Object Not Found

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About