in reply to How to send HTTP POST request?
As others have mentioned, you can use LWP to post data. I thought it might be useful to give you an example of some code I've used in the past (please keep in mind I am far from an expert in this area, so I'm sure others could provide better (or at least alternative) examples):
my $ua = LWP::UserAgent->new; $ua->timeout( 600 ); my $reqobj = $ua->post( 'http://somewebsite/page.cgi', { Var1 => $value1, Var2 => $value2, Submit => 'Process query', } ); if( ${$reqobj}{_msg} ne 'OK' ) { print "\nerror posting data: ${$reqobj}{_msg}\n"; return 1; } my $results = ${ $reqobj }{_content};
The values submitted in the post method are placed in the hash that follows the URL. The website that I was using required a Submit field with the value of Process query (generated when the user hit the 'Submit' button) in order for the CGI script to process the data and return the results, so you might want to keep that in mind as your site might require something similar. Note you can test _msg for success/failure, and _content contains the results. Finally, you probably do not need to change the default setting for the timeout value of the request, but in the example above I set the timeout value to 600 seconds (10 min) (the site I was using typically takes 5-8 min to process a request).
HTH - good luck.
|
|---|