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

Problem submitting a form

Thread Next
From:
Steve Borruso
Date:
March 21, 2001 19:28
Subject:
Problem submitting a form
Message ID:
3AB96E12.E494922B@stny.rr.com
Greetings,

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
   page.

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

Thanks,
Steve

Here's my script ....

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

etc..........

#-----------------------------------------------------------
# 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 =>
1));
my $r = $ua->simple_request(POST "http://www.bidville.com/login.cfm",
        {
         url => '',
         nickname => "$myuserid"',
         password => '$mypass",
         });
while ($r->is_redirect) {
  my $u = $r->header('location') or die "missing location: ",
$r->as_string;
  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 =
'http://www.bidville.com/blah.cfm?Name1=Value1&Name2=Value2 .....';
$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,'http://www.bidville.com');
$r = $ua->simple_request($form->click());

print $r-> as_string;

exit;

Here's the latest output ...

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

Error Occurred While Processing Request

 Error Diagnostic Information

 An error has occurred.

 HTTP/1.0 404 Object Not Found


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About