Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

STDOUT to a remote CGI

Status
Not open for further replies.

PGen

Programmer
Aug 31, 2001
39
GB
I need urgent help with STDOUT?

Is it possible to stream text output to a remote CGI, if so how?

I am hoping this is what i need to simulate a form data submission.

Simualated to keep the data transfer server side because of security and performance.


Many many thanks folks,

Will
 
You can use the LWP library module to perform a POST operation to a remote CGI script. I think that's exactly what you want to do. Here's some code that I use to "call" a remote cgi program:
Code:
my $domain = "[URL unfurl="true"]http://www.mydomain.com";[/URL]
my $cgidir = "/cgi-bin";
my $cgipgm = "RemoteProg.pl";
my %form = ();

my %form = ( FUNCTION => "rename", OLDNAME => $oldname, NEWNAME => $newname );
}

use URI::URL;
use LWP::UserAgent;
my $ua = new LWP::UserAgent;

my $tmpurl = url("http:");
$tmpurl->query_form(%form);
my $req = new HTTP::Request 'POST', "$domain$cgidir/$cgipgm";
$req->content_type('application/x-[URL unfurl="true"]www-form-urlencoded');[/URL]
$req->content($tmpurl->equery);

my $res = $ua->request($req);
if ( $res->is_success ) {
	$returnData = $res->as_string;
} else {
	$Ret{'Error'} = "HTTP error: " . $res->code . " " . $res->message;
	$Ret{'Return'} = 0;
	print &quot;<b>RemoteProg: Error: </b>&quot; . $Ret{'Error'} . &quot;<br><br>&quot; if $debug;
	return \%Ret;
}
You can parse the string $returnData to determine exactly what the remote program returned.
Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
The specified CGI application misbehaved by not returning a complete set of HTTP headers. The headers it did return are:


Can't locate object method &quot;new&quot; via package &quot;http::Request&quot; at d:\inetpub\fp04-144\test\tracy.pl line 15.


Thats this line...
my $req = new http::Request 'POST', &quot;$domain$cgidir/$cgipgm&quot;;


Is this a bridging script? I post to this and it forwards the data on to a cgi, and reads the reply?
 
No, it isn't a bridging script. The example code I gave above should send an http post request to the cgi program, and get back it's response. I'm assuming you set the $domain, $cgidir and $program variables to the correct values, and substituted your own parameter names and values in the %form assignment statement? These are the lines you need to change:
Code:
my $domain = &quot;[URL unfurl="true"]http://www.mydomain.com&quot;;[/URL]
my $cgidir = &quot;/cgi-bin&quot;;
my $cgipgm = &quot;RemoteProg.pl&quot;;

my %form = ( FUNCTION => &quot;rename&quot;, OLDNAME => $oldname, NEWNAME => $newname );
}
The format for the parameters (%form) is:
Code:
parameter-name => &quot;parameter-value&quot;,
Other than that I'm not sure what might be wrong. If you still have a problem, post some of your code.
Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
The module isnt installed on the remote server. Im going to try it locally.

Where can I get it from ?
Can it be run on PWS ?

Thanks Tracy
 
You can get the module from If you're running activeperl you can install it directly using the ppm program, but I don't remember exactly how to do that. Once installed it should work ok on pws. Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top