Solved

POSTing from a Perlscript --Urgent--

Posted on 2000-05-09
4
176 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
perl to mysql 5 130
perl rename 2 142
Expect & sshpass package for Solaris 10 x86 15 893
Perl script to delete older files 6 71
I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

911 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now