Solved

POSTing from a Perlscript --Urgent--

Posted on 2000-05-09
4
181 Views
Last Modified: 2010-03-05
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.

0
Comment
Question by:Tuba
  • 2
4 Comments
 
LVL 16

Expert Comment

by:maneshr
ID: 2793509
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.

===============my_form.asp
<%@ LANGUAGE = PerlScript%>
<HTML>
<HEAD><TITLE>Request Object</TITLE></HEAD>

<BODY> <BODY BGCOLOR=#FFFFFF>

<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");
    }
%>

<CENTER>
<FORM ACTION="wform.asp" METHOD="POST">
<INPUT TYPE="Textfield" NAME="Yourname" MAXLENGTH="30" VALUE="Enter Your Name Here">
<INPUT TYPE="SUBMIT" VALUE="Click Me">
</FORM>
</CENTER>


<!-- +++++++++++++++++++++++++++++++++++++
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;
      s/[\/\\](\w*\.asp\Z)//m;
      $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>  

</BODY>
</HTML>

==================

Hope that helps
0
 
LVL 6

Accepted Solution

by:
christopher sagayam earned 300 total points
ID: 2793849
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 => 'http://www.perl.com/cgi-bin/BugGlimpse';
  $req->content_type('application/x-www-form-urlencoded');
  $req->content('match=www&errors=0');


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.

0
 

Author Comment

by:Tuba
ID: 2794257
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.

Thanks!

0
 
LVL 6

Expert Comment

by:christopher sagayam
ID: 2795171
well it is there in the activeperl docs

section "LWP"
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question