POSTing from a Perlscript --Urgent--

I need to POST data to a server from a Perlscript, i.e. I need to mimic a user pressing "Submit". I use Active Perl on NT if it makes a difference.

Who is Participating?
christopher sagayamConnect With a Mentor Commented:
straight from the activeperl docs

# Create a user agent object
  use LWP::UserAgent;
  $ua = new LWP::UserAgent;
  $ua->agent("AgentName/0.1 " . $ua->agent);

  # Create a request
  my $req = new HTTP::Request POST => '';

here is where you PASS the FORM variables example match , errors etc and etc

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

$res->content contains the OUTPUT from the server ..HTML page etc ..

  # Check the outcome of the response
  if ($res->is_success) {
      print $res->content;
  } else {
      print "Bad luck this time\n";

The $ua is created once when the application starts up. New request objects should normally created for each request sent.

PerlScript is an ActiveX scripting engine that lets you write PerlScript code for any ActiveX host, including servers and browsers. PerlScript joins the ranks of JavaScript and Visual Basic Script as an easy-to-use Web scripting language.

here is an example using which you can learn how to gather data from and provide web HTML forms for the client.

<%@ LANGUAGE = PerlScript%>
<HEAD><TITLE>Request Object</TITLE></HEAD>


<H3>Web Forms Example</H3><P>

    my($name) = $Request->Form('Yourname')->Item();
    $name = $Server->HTMLEncode($name);

    if($name eq 'Enter Your name here') {
    $Response->Write("Please type your name in the box below and then press the button");
    else {
    $Response->Write("Hello $name");

<INPUT TYPE="Textfield" NAME="Yourname" MAXLENGTH="30" VALUE="Enter Your Name Here">

<!-- +++++++++++++++++++++++++++++++++++++
here is the standard showsource link -
      Note that PerlScript must be the default language --> <hr>
      $url = $Request->ServerVariables('PATH_INFO')->item;
      $_ = $Request->ServerVariables('PATH_TRANSLATED')->item;
      $params = 'filename='."$1".'&URL='."$url";
      $params =~ s#([^a-zA-Z0-9&_.:%/-\\]{1})#uc '%' . unpack('H2', $1)#eg;
<A HREF="index.htm"> Return </A>
<A HREF="showsource.asp?<%=$params%>">
<h4><i>view the source</i></h4></A>  



Hope that helps
TubaAuthor Commented:
Qouting from the manual borders on cheating, but I'm satisfied with the answer. Could I have the name of the section in the manual, please.


christopher sagayamCommented:
well it is there in the activeperl docs

section "LWP"
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.