Michael Stone hit the nail on the head:

Thanks much, Mike. This code worked and I now have it as the foundation of
my script, surely to be reused in other places. Concise, neat, splendid.

Thanks very much,
Jack


> > The CGI script on the other server must be called with POST, not GET. It
> > seems like the logic would be something like this:
> >
> > 1. send POST string to other server, with variables attached. So other
> > server would receive a POST like:
> >   http://www.otherserver.com/cgi-bin/script?name=variable
>
>
> this is your first problem.. what you're doing is tacking input onto the
> end of a URL with a query mark.   that's functional, but it uses the GET
> method, rather than POST.   the data for a POST has to be sent as a
> separate part of the HTTP request sequence:
>
>     POST http://www.otherserver.com/cgi-bin/script HTTP/1.0
>     Content-length: 10
>
>     1234567890
>
>
>
> data sent using the GET method is passed to the script in either the
> variable $ENV{'QUERY_STRING'}, or the array of command-line arguments
> @ARGV.
>
> POST data, by contrast, is passed to the script as a stream, which can
> be read by pulling information from STDIN.
>
> there's no way to re-target those two forms of input.. they're handled
> behind the scenes by the httpd after the client's connection has been
> handled, and before the script ever gets launched.
>
>
> this should do ya:
>
>
> #!/usr/local/bin/perl
>
> use  Socket;
>
> ####  CONFIG DATA  ####
>
> $PORT   = 80;
> $SERVER = 'www.yawp.com';
> $URL    = '/cgi-bin/echo';
>
>
> ####  MAIN CODE  ####
>
> $remote_data = &post_request ($URL, "this+is+a+test");
> print "THE ANSWER WAS: \n\n", $remote_data, "\n\n";
>
>
>
> ####  GEEKISH SOCKET STUFF  ####
>
>
> $err[0] = "can't open a socket";
> $err[1] = "couldn't connect to server";
>
> sub post_request {
>     my $url  = shift;
>     my $data = shift;
>
>     ####  do the magic socket dance  ####
>     $iaddr = inet_aton ($SERVER);
>     $paddr = sockaddr_in ($PORT, $iaddr);
>     $proto = getprotobyname ('tcp');
>     socket (SOCK, PF_INET, SOCK_STREAM, $proto) or die qq($err[0]: $!);
>     connect (SOCK, $paddr) or die qq($err[1]: $!);
>     $std = select (SOCK);  $| = 1;  select ($std);
>
>     ####  assemble the HTTP query  ####
>     my @request =  ();
>     push @request, "POST $url HTTP/1.0\n";
>     push @request, "Content-length: " . length ($data) . "\n\n";
>     push @request, "$data\n";
>     my $query   =  join ('', @request);
>
>     ####  send the request  ####
>     print SOCK $query;
>
>     ####  read the entire reply into a scalar  ####
>     my $tmp = $/;  undef $/;
>     my $reply = <SOCK>;
>     $/ = $tmp;
>
>     ####  clean up & return the data  ####
>     close SOCK;
>     return $reply;
> }
>
>
>
> __END__
>
>
>
>
>
>
> mike stone  <[EMAIL PROTECTED]>   'net geek..
> been there, done that,  have network, will travel.

____________________________________________________________________
--------------------------------------------------------------------
 Join The Web Consultants Association :  Register on our web site Now
Web Consultants Web Site : http://just4u.com/webconsultants
If you lose the instructions All subscription/unsubscribing can be done
directly from our website for all our lists.
---------------------------------------------------------------------

Reply via email to