Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

POSTing from a Perlscript --Urgent--

Posted on 2000-05-09
4
Medium Priority
?
195 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 1200 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

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.

Question has a verified solution.

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

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
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…
Six Sigma Control Plans

885 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