473,385 Members | 1,824 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Script calling CGI

27
Hi There,
I need to send some parameters from a Perl program to another Perl program that's in cgi-bin. I'm trying to do an http request, but it's not working properly. Any ideas?

Palm.
Mar 14 '07 #1
16 2408
KevinADC
4,059 Expert 2GB
No ideas without seeing your code or explaining what "not working properly" means.
Mar 14 '07 #2
palm
27
Hi there,
I've a perl program called send.pl in a unix directory (in /usr/main/laal/work) and another perl program called receive.pl on the web server (in /usr/docs/www/cgi-bin). I need to send some values from send.pl to receive.pl. I like to use http request to call receive.pl and send the values something like this:

http://abcd.com/cgi-bin/receive.pl?total=789456&name=jack&computer=desktop

I'm a new programmer and I've no idea about how to create http request and send the values to the other program. Could any one please help me out?

Thank You.

Palm.
Mar 14 '07 #3
miller
1,089 Expert 1GB
Hello palm,

That was much more clear.

Ok, it sounds like all you need is an introduction to LWP. This is a set of cpan modules typically used to process web pages. You can do a lot of things with them, so take a moment to browse around all the other modules in the package at some point. But for now, I would simply point you to this:

cpan LWP::Simple

If you need help installing this module, look at cpanfaq.

cpanfaq How to install perl modules

- Miller
Mar 14 '07 #4
KevinADC
4,059 Expert 2GB
Ditto Miller :)
Mar 14 '07 #5
palm
27
Hi Kevin & Miller,
I'm a new programer so I'm having little hard time in getting through this. I wrote this code and tried to send the parameters but i'm getting some message like The requested document was not found, etc etc.. This is what I've written:

Expand|Select|Wrap|Line Numbers
  1. #! /usr/bin/perl -w
  2. use strict;
  3.  
  4.  use LWP::UserAgent;
  5.  my $ua = LWP::UserAgent->new;
  6.   my $req = HTTP::Request->new(POST => 'http://abcd.com/cgi-bin/receive.pl');
  7.   my $res = $ua->request($req);
  8.   print $res->as_string;
  9.  
how can I send the parameters to receive.pl from this code(parameters: total, name, computer, etc)?. I'm totally lost....

Palm.
Mar 14 '07 #6
miller
1,089 Expert 1GB
Hi Palm,

You're almost there. This is how I would suggest that you do it:

Expand|Select|Wrap|Line Numbers
  1. #! /usr/bin/perl -w
  2. use strict;
  3.  
  4. use HTTP::Request::Common qw(POST);
  5. use LWP::UserAgent;
  6.  
  7. my $ua = new LWP::UserAgent;
  8. $ua->agent("send.pl/1.0");
  9.  
  10. # Create HTTP POST request
  11. my $req = POST "http://abcd.com/cgi-bin/receive.pl", [
  12.     total        => 789456,
  13.     name        => 'jack',
  14.     computer    => 'desktop',
  15. ];
  16. my $res = $ua->request($req);
  17.  
  18. if($res->is_success) {
  19.     print "Content = '" . $res->content . "'";
  20. } else {
  21.     print "Error = '" . $res->status_line . "'";
  22. }
  23.  
Note: This code is untested.

- Miller
Mar 14 '07 #7
miller
1,089 Expert 1GB
You can find documentation of this method of posting at the following locations:

cpan LWP::UserAgent #Request Methods
cpan lwpcook #POST

- Miller
Mar 14 '07 #8
palm
27
Hi Miller,
Thanks a lot for your help. I tried those steps and getting '404 not found' error message. I used those steps in my send.pl and I wrote the following code for receive.pl. I'm not sure where the problem is:

#! /usr/bin/perl -w
use strict;
use LWP::UserAgent;
use HTTP::Request::Common;
use URI;

my $ua = LWP::UserAgent->new;
my $uri = URI->new('http://abcd.com/cgi-bin/receive.pl');

my $response = $ua->simple_request(GET $uri);
print $response->content;


I really appreciate your help. Please let me know if you've any idea.

Palm.
Mar 19 '07 #9
palm
27
Hi There,
I've a perl program called "receive.pl", which is supposed to get some variables from another program called "send.pl". When I run my receive.pl, I'm getting page not found error message. Since I'm new to programming, it'll be great if any one could help me out. This is how my receive.pl looks like:

Expand|Select|Wrap|Line Numbers
  1. #! /usr/bin/perl 
  2. use strict;
  3.  
  4. use LWP::UserAgent;
  5. use HTTP::Request::Common;
  6. use URI;
  7.  
  8. my $ua = LWP::UserAgent->new;
  9. my $uri = URI->new('http://abcd.com/cgi-bin/receive.pl');
  10. my $response = $ua->simple_request(GET $uri);
  11. print $response->content;
  12.  
I've doubt in this line:
my $uri = URI->new('http://abcd.com/cgi-bin/receive.pl');

My current program is called receive.pl and i'm creating new URI using this name. I'm lost here. Can anyone please help me?

Thank You.

Palm.
Mar 21 '07 #10
KevinADC
4,059 Expert 2GB
seems you already asked question this in your other thread.
Mar 21 '07 #11
miller
1,089 Expert 1GB
Hi palm,

Please do not double post your threads. Instead, continue in the thread you've already started for the problem.

I'm merging the threads now.

- Miller
Mar 21 '07 #12
palm
27
Sorry Miller,
I couldn't find a solution so I thought I better divide the probem into small parts and start a new discussion. I'll continue posting in this old topic then.

Thankz.

Palm.
Mar 22 '07 #13
palm
27
Hi there,
Now both programs are working with out any errors, but I don't see/get the variables (total=789456,name='jack',computer= 'desktop'). How can I get them in receive.pl? response-> content doesn't seem working.

Palm.
Mar 22 '07 #14
palm
27
Hi There,
I tried to get/print the variables in the http request like this:

use CGI qw/:standard/;
my $cgi = new CGI;
..
..
..

print $cgi->param("total");
print $cgi->param("name");
print $cgi->param("computer");

but it's not printing anything. I'm totally lost. I'm I missing anythig? Please some one help me with this problem.


Palm.
Mar 27 '07 #15
palm
27
Hi There,
I'm new to Perl and I just wrote few lines to do an http request. The code is working fine and I'm trying to save the variables (param('age')). They just show up inside the html page, but not as an out put in the screen editor. What do I have to do inorder to get them printed in the editor or save to a file? This is my variable in Perl:

my $age = $cgi->param('age');

when I say "print $age" in Perl, it's printing space, but when I say like this in html:

<BODY>
<P>$age</P>

it's printing the age in the web. I want to print the variable on the screen/to a file. Does any one know how to fix it?

Palm.
Mar 28 '07 #16
KevinADC
4,059 Expert 2GB
Palm,

your questions are very basic. You need to maybe slow down and read some basic perl primers and become familiar with the perl and perl module documentation. All can be found at the perldoc website:

http://perldoc.perl.org/

if you have a local installation of perl all the documentation comes along with perl so you can also read it on your local computer.
Mar 28 '07 #17

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: deko | last post by:
In regard to running php scripts with cron - Here is a sample script: <?php //debug.php echo "<br> This is a test"; ?> I can call debug.php from a web page on my site like this:
12
by: bhennon | last post by:
Hey all, I have a small php script that calls a random image at the following page. http://www.2006ymcanationals.com/random.php IT WORKS IF I go directly to the above link. I am trying to...
2
by: Ola Fjelddahl | last post by:
hi. I load a script dynamically and it works * everytime with IE6. * sometimes! with Mozilla1.5 <- makes me curious * never with Opera7.11 all tests on WindowsXP. With "sometimes" I mean
8
by: Jakej | last post by:
I've been using a javascript in an html file for a banner slider, and it works as desired. But I'd like to use it on more than one page and it would be great if I could transfer the code to a .js...
8
by: Brett Robichaud | last post by:
I understand how code-behind can handle events for a page, but can I call a code-behind method from within a <script> tag in my ASP.Net page, or can I only call methods defined in other <script>...
4
by: Miguel Dias Moura | last post by:
Hi, I just uploaded a web site and i am getting an error. I have a script which sends form values to an email using AspNetEmail. The script was working when i was calling the script like...
3
by: Dustin II. | last post by:
Hi, I have an ASP.NET solution, and the ASPX page I have a form , I want to copy some of the data from that form to the clipboard, I am using the below script the script works fine when I use a...
17
by: comp.lang.tcl | last post by:
The TCL command I am using will do a command-line action on a PHP script: set cannotRunPHP I have to do it this way as both the TCL script and the PHP script run as CLI. However, "info.php"...
18
by: Ed Jay | last post by:
<disclaimer>js newbie</disclaimer> My page has a form comprised of several radio buttons. I want to poll the buttons to determine which button was selected and convert its value to a string. I...
12
by: Iddo | last post by:
Hi, I am having a strange problem... I have an HTML file which has 2 script tags: 1) <script language="javascript" id="ABC" src="ABC.js" /> 2) <script id="general" language="javascript">...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.