Re: Problem submitting a form

Dave Faraldo (dfaraldo@nocpulse.com)
Thu, 22 Mar 2001 09:57:43 -0800


Try adding a 'use LWP::Debug qw(+);' to see what your script is doing.
(Did it get the right URL?  Is it posting the correct form data?  Is
it sending the login cookie?  Etc.)  For instance, if you really used
'blah.cfm' in your second request, you would indeed get 404 Not Found.
:-)

                                	-=< Dave >=-



Original message follows:
-------------------------
> Date:  Wed, 21 Mar 2001 22:14:26 -0500
> From:  Steve Borruso <sborruso@stny.rr.com>
> Subject:  Problem submitting a form

> 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..........
> 
> #-----------------------------------------------------------
Is it passing
> # 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
> 
>