Solved

POST action

Posted on 2002-05-29
7
169 Views
Last Modified: 2010-03-05
Instead of going to a website, type in with some info, and click on send button, is it possible for me to write a script such that it'll post the data the same way the webpage does it?

Right now, I have a cgi perl script that accepts input from a webpage.  It accepts 2 fields that will be used in the perl script.

Please advise.
yam
0
Comment
Question by:YamSeng
7 Comments
 
LVL 51

Expert Comment

by:ahoffmann
ID: 7044170
0
 
LVL 1

Expert Comment

by:GorGor1
ID: 7044450
Note that that doesn't always work.  I have code in my perl scripts that will not allow someone to include the parameters directly in the URL.
0
 
LVL 4

Accepted Solution

by:
dda earned 50 total points
ID: 7046486
use HTML::Form;

my $form = HTML::Form->parse($html,$url);
$form->value('login','yourlogin');
$form->value('password','yourpass');
$form->value('action','login');
my $req = $form->click;

etc., etc.

Hope this helps.
0
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.

 
LVL 1

Author Comment

by:YamSeng
ID: 7046537
ahoffmann, where should I put that line in?  a csh script?  or perl script? just that 1 line?

dda, I'll try that out.
From my understanding, you are trying to fill in the details for the form I should have online, and clicking the submit button. (correct me if I'm wrong).
0
 
LVL 4

Expert Comment

by:dda
ID: 7046550
Yes, correct. You will need to use other modules as well:

use HTML::Form;
use LWP;

my $ua = LWP::UserAgent->new();
$ua->agent('Mozilla');

my $url = 'http://somewhere.com/script.cgi'; #
my $login_req = HTTP::Request->new(GET => $url);
my $login_res = $ua->request($login_req);
my $html = $login_res->content;

my $form = HTML::Form->parse($html,$url);
$form->value('login','yourlogin');
$form->value('password','yourpass');
$form->value('action','login');
my $req = $form->click;

my $res = $ua->request($req);
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 7049734
> .. put that line in?  a csh script?  or perl script?
you said you still have a perl script, so that script would be the best place 'cause you still have variable names and values there too.
Use the example suggested by dda.
If you have wget you also might use:
  system("wget http://www.som.dom/path/to/your.cgi?name-of-field1=value-of-field1&name-of-field2=value-of-field2 ");

not as elegant as LWP, but quick&dirty ;-)
0
 
LVL 8

Expert Comment

by:jhurst
ID: 7065426
As I read the question all the answerers so far are missing something.  Buy maybe it is me.  If you actually want your script, not another page, to do the post then this is what you need to do, and forget extra pages.

I have a sub that I use as follows:
sub doAPost {                   #post to _[0], the data in $_[1]

  # Create a user agent object
  use LWP::UserAgent;

  $hdrs=new HTTP::Headers(User_Agent => 'ResourceDataBrowser',
  Referer=>"http://$ENV{HTTP_HOST}");

  $ua = LWP::UserAgent->new;

  # Create a request
  my $req = HTTP::Request->new(POST => $_[0],$hdrs);
  $req->content_type('application/x-www-form-urlencoded');
  $req->content($_[1]);

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

  # Check the outcome of the response
  if ($res->is_success) {
    return $res->content;
    }
  else {
    return -1;
    }
  }


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

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 …
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

895 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

15 Experts available now in Live!

Get 1:1 Help Now