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

I see that some form gives arguments to a cgi script using the method POST I need to simulate this form submission, retrieve the results and display it in the way I want to. If it allowed GET method, I would do it with a simple usage of get in the LWP::Simple module, but with a longer url... I use CGI and LWP::Simple, is it possible to do that? thanx.

Replies are listed 'Best First'.
Re: form fill simulation with perl
by davorg (Chancellor) on Aug 10, 2004 at 07:49 UTC

    LWP::Simple doesn't support the POST method. You'll need to use LWP::UserAgent and HTTP::Request as described in lwpcook.

    Another alternative might be to look at WWW::Mechanize.

    --
    <http://www.dave.org.uk>

    "The first rule of Perl club is you do not talk about Perl club."
    -- Chip Salzenberg

      LWP::Simple doesn't support the POST method.
      Well, it sorta does, with a couple of extra steps:
      use LWP::Simple qw($ua); my $content = $ua->post("http://www.example.com", [first_name => 'Randal', last_name => 'Schwartz'])->content;
      Of course, all you're getting here is a LWP::UserAgent created for you, and the right modules brought in with one use line.

      -- Randal L. Schwartz, Perl hacker
      Be sure to read my standard disclaimer if this is a reply.

Re: form fill simulation with perl
by alexrait1 (Initiate) on Aug 10, 2004 at 18:46 UTC
    thanx, it worked with LWP::UserAgent, but now I have another problem with it, sometimes I get this response: HTTP/1.1 302 Found Connection: close Date: Tue, 10 Aug 2004 18:27:57 GMT Via: 1.1 netcache1 (NetCache NetApp/5.5R5D11) Location: index.php Server: Apache Content-Type: text/html Client-Date: Wed, 11 Aug 2004 21:40:47 GMT Client-Peer: 64.191.74.245:80 Client-Response-Num: 1 Client-Transfer-Encoding: chunked X-Powered-By: PHP/4.3.5 and sometimes it works ok... what can be the problem?