POST action

Instead of going to a website, type in with some info, and click on send button, is it possible for me to write a script such that it'll post the data the same way the webpage does it?

Right now, I have a cgi perl script that accepts input from a webpage.  It accepts 2 fields that will be used in the perl script.

Please advise.
Who is Participating?

Improve company productivity with a Business Account.Sign Up

ddaConnect With a Mentor Commented:
use HTML::Form;

my $form = HTML::Form->parse($html,$url);
my $req = $form->click;

etc., etc.

Hope this helps.
Note that that doesn't always work.  I have code in my perl scripts that will not allow someone to include the parameters directly in the URL.
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

YamSengAuthor Commented:
ahoffmann, where should I put that line in?  a csh script?  or perl script? just that 1 line?

dda, I'll try that out.
From my understanding, you are trying to fill in the details for the form I should have online, and clicking the submit button. (correct me if I'm wrong).
Yes, correct. You will need to use other modules as well:

use HTML::Form;
use LWP;

my $ua = LWP::UserAgent->new();

my $url = ''; #
my $login_req = HTTP::Request->new(GET => $url);
my $login_res = $ua->request($login_req);
my $html = $login_res->content;

my $form = HTML::Form->parse($html,$url);
my $req = $form->click;

my $res = $ua->request($req);
> .. put that line in?  a csh script?  or perl script?
you said you still have a perl script, so that script would be the best place 'cause you still have variable names and values there too.
Use the example suggested by dda.
If you have wget you also might use:
  system("wget http://www.som.dom/path/to/your.cgi?name-of-field1=value-of-field1&name-of-field2=value-of-field2 ");

not as elegant as LWP, but quick&dirty ;-)
As I read the question all the answerers so far are missing something.  Buy maybe it is me.  If you actually want your script, not another page, to do the post then this is what you need to do, and forget extra pages.

I have a sub that I use as follows:
sub doAPost {                   #post to _[0], the data in $_[1]

  # Create a user agent object
  use LWP::UserAgent;

  $hdrs=new HTTP::Headers(User_Agent => 'ResourceDataBrowser',

  $ua = LWP::UserAgent->new;

  # Create a request
  my $req = HTTP::Request->new(POST => $_[0],$hdrs);

  # Pass request to the user agent and get a response back
  my $res = $ua->request($req);

  # Check the outcome of the response
  if ($res->is_success) {
    return $res->content;
  else {
    return -1;

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.