Solved

POSTing from a Perlscript --Urgent--

Posted on 2000-05-09
4
168 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
well it is there in the activeperl docs

section "LWP"
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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.…
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…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

763 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

11 Experts available now in Live!

Get 1:1 Help Now