Home: Perl Programming Help: Intermediate:
Simulating a POST action


Mar 24, 2000, 5:20 PM

Views: 1492
Simulating a POST action

Hi and many thanks in advance to one and all Smile

What I would like to do is have a program which parses the HTML of a webpage, the webpage being retrieved using LWP::Simple and the get command.

However, if the webpage being retrieved was generated by a CGI script given certain query data, how can I pass data to the script if it requires the POST action to be used? Smile

Obviously for a GET action I would include the data in the URL I requested, eg:

use LWP::Simple;


But how can I run the script using the POST action rather than GET? Smile

Thanks all Smile


Mar 24, 2000, 5:38 PM

Views: 1492
Re: Simulating a POST action

You can't use LWP::Simple for this. You'll need LWP::UserAgent. Example:

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>

use LWP::UserAgent;

$client = new LWP::UserAgent;
$req = new HTTP::Request POST => "http://www.server.com/cgi-bin/prog.cgi", [ name => "jeff", age => 18 ];
$return = $client->request($req);

Read the lwpcook documentation that comes with the LWP suite of modules.