in reply to How to get a local form to be 'clicked'?

I'll assume that you have the relevant fields already filled in in your HTML file.

What you really want then, is send a HTTP request (GET or POST) that will send the data from the form to an URL on the web. And I wouldn't use HTML::Form for this kind of thing. (except when the html form is changing a lot - but then you probably wouldn't have it on your local filesystem).

The simplest way is probably

Collect all the data in the local form (you can probably just hard-code this in your script) and do a

use LWP::Simple; getprint "http://www.someurl.org/scriptname?param1=value1&param2=value +2"
This will send a GET request with the parameters encoded in the URL. Note that you will have to escape special characters in urlencoding. You might use the URI module for that.

See also

perldoc LWP::Simple perldoc URI
-- Joost downtime n. The period during which a system is error-free and immune from user input.

Replies are listed 'Best First'.
Re: Re: How to get a local form to be 'clicked'?
by Anonymous Monk on Jun 06, 2002 at 08:10 UTC
    Of course I tried $stmt=get("http:...?field1=val1&filed2=val2");
    But this is detected as a not correct request and answered
    with a "failed-Login" html-page by the server, even in a browser:
    within the form method has to be set: method="post"

    I just have to load the local form into UserAgent and perfom an request(form->click),
    but HOW (?) can I load that damn local html-form-file?
    Isn't that just a simple thing?

    I tried:
    $req = HTTP::Request->new(GET => 'file:/home/../myForm.html'); $res = $ua->request($req);

    But $req contains: GET 'file:/home/../myForm.html'
    and then this crashes: $ua->request($req)
    Carl
      First of all, you can aslo make custom POST requests with LWP::UserAgent by using the $ua->post() call, which will also take parameters as arguments. - I would probably go for that option.

      Second, them HTML::Form documentation is not very clear on exactly what should be passed to HTML::Form->parse(), but a little browsing in the source gives me this working code:

      open HTML,"<./index.html" or die $!; my @forms = HTML::Form->parse(*HTML,'http://localhost/'); close HTML;
      Where the first argument to parse() is the typeglob that contains the filehandle of the HTML file, and the second argument is the base url, which is needed to resolve relative urls in the form.

      Hope this helps :-)

      -- Joost downtime n. The period during which a system is error-free and immune from user input.
      Got it, thank you for your support. This works:
      $res=$ua->request(POST 'http://..asp',[field1=>'val1',field2=>'val2]);

      carl