Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Uhm....i want to do something and I am not sure it's possible, but if +it is, I sure would like to know how. So there goes... I have 2 html pages: Page A and Page B. Page B is a form processing sc +ript. Page A is a redirect page which jumps to page B with header->lo +cation clause. I am wonderig if it's possible to simmulate a form sub +mission with perl. I would have done it with url params like PageB.pl?id1=value1&id2=value2, but one of the params is a password wh +ich I don't want to be exposed. I think I used to do similar things i +n Coldfusion some time ago via <_CFHTTP> tag. Can I do it in perl?

Replies are listed 'Best First'.
(Ovid) Re: Form submission simmulation
by Ovid (Cardinal) on Sep 12, 2000 at 09:14 UTC
    Yes, you can simulate form submissions in Perl. You can use LWP::Simple for get requests, which is what you appear to need here. The basic syntax is like the following:
    use LWP::Simple; use URI::URL; my $url = url('http://www.perlmonks.org/index.pl?node_id=32057&lastnod +e_id=3628'); # Yes, the following is insecure and can be sniffed! $url->query_form(username => 'joe', password => 'schmoe'); $content = get($url);
    If you need a post request, you should use LWP::UserAgent.

    The problem you have is the password. If you're using HTTP authentication, you should use the LWP::UserAgent module, which can easily handle said authentication (I am assuming that your issue is not wanting to send the password as plaintext). There is a way to do form submission with Perl over a secure server, but I can't find the reference right now :(

    If you'd like to know the nitty-gritty about Web automation, check out Web Client Programming with Perl which is out of print, but available through the O'Reilly Open Books Project (how many publishers do you know who release out-of-print books for free over the web?).

    Cheers,
    Ovid

    Join the Perlmonks Setiathome Group or just go the the link and check out our stats.

Re: Form submission simmulation
by wardk (Deacon) on Sep 12, 2000 at 21:29 UTC

    If you use the CGI module, you can invoke the script from a command line and either pass the variables en-masse or be prompted for them. It's great for testing when you don't have access to a webserver. Either read the output on the screen, or pipe the output to a file and point your browser at the file for display.

    perlCGIscript.pl foo=bar foo2=bar2 this=that

    As far as handling the password...I think there have been many approaches listed on other nodes, I don't have any suggestions for that at this time.

    happy testing!

Re: Form submission simmulation
by Cheburashka (Acolyte) on Sep 12, 2000 at 11:27 UTC
    Hm...somehow it doesn't find these modules use LWP::Simple; use URI::URL; are they part of the language or I have to download them?
      You'll get them from CPAN...

      /brother t0mas
      If you are using ActiveState Perl for Windows, it should be installed, otherwise use `ppm` to install the package...

      Jouke Visser, Perl 'Adept'
Re: Form submission simmulation
by Incognito (Pilgrim) on Nov 21, 2001 at 02:17 UTC

    This is the same question as How to POST to a web server? and you can find fully documented code and samples here. I provide sample Perl and ASP (or HTML) code to submit contents (from a simulated Page A) to Page B (the ASP page which takes the submitted/POSTed contents and does something with them)...

    You need to POST since you don't want to expose the values via the URL.