FG has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I would like to write a script that sends information to two websites. Basically, I need to send an entry from a form to be processed by two scripts in two different hosts. Any ideas on how I could get started? (give me a push and I'll get rolling...) Thanks! FG

Edited 2002-06-10 by mirod: changed the title.

  • Comment on How to send data to 2 websites (was:Can anyone help?)

Replies are listed 'Best First'.
Re: Can anyone help?
by vladb (Vicar) on Jun 10, 2002 at 20:47 UTC
    Take a look at either HTTP::Request or HTTP::Request::Form modules. I'm quite positive they will help you. The first module, for example, could be used to send data received from a form by a CGI Perl script to any other HTTP scripts of your choosing by simply creating a couple request objects for each script on two different 'hosts' and 'attaching' the form data with the request.

    The other module (the Request::Form one), allows you to submit HTTP forms from inside a Perl script. However, I haven't used it much personally, therefore can't tell more than what the docs say.

    Hope this is enough of a push! ;-)

    UPDATE: For example, you could make use of a code similar to this:
    use CGI; use LWP::UserAgent; use HTTP::Request; my @hosts = qw( http://www.hosta.com/cgi-bin/scripta.pl http://www.hostb.com/cgi-bin/scriptb.pl ); my $cgi = new CGI; $ua = LWP::UserAgent->new; my $content = ""; # Build your content here! # Example, # build content from form values submitted to this script: $content = "foo_field=" . $cgi->param('foo_field') ."bar_field=" . $cgi->param('bar_field'); for $host_script (@hosts) { my $req = HTTP::Request->new (POST => $host_script); $req->content($content); # Verify if request was successful.. if ($req->is_success()) { print "Did well\n"; } else { print "Didn't do well\n"; } }
    (Althought not tested) this could be the script you submit your form to first. The script will then 're-submit' form data to selected scripts on other hosts.

    _____________________
    $"=q;grep;;$,=q"grep";for(`find . -name ".saves*~"`){s;$/;;;/(.*-(\d+) +-.*)$/; $_=["ps -e -o pid | "," $2 | "," -v "," "];`@$_`?{print"+ $1"}:{print" +- $1"}&&`rm $1`; print$\;}
Re: Can anyone help?
by dsheroh (Monsignor) on Jun 10, 2002 at 20:56 UTC
    Check out LWP::Simple or, if you need more control, LWP::UserAgent.
    #!/usr/bin/perl -w use strict; use LWP::Simple; my $result = get("http://server.com/document?param=value");
    or, to go all-out,
    #!/usr/bin/perl -w use strict; use LWP::UserAgent; use HTTP::Request; use URI; my $ua = new LWP::UserAgent; my $url = URI->new("http://server.com/document"); $url->query->form(param => 'value'); my $req = HTTP::Request->new(POST => $url); my $resp = $ua->request($req); print STDERR $resp->error_as_HTML() if $resp->is_error();
    That enough of a push?
(ichi) Re: web clients in Perl (was: 'Can anyone help?')
by ichimunki (Priest) on Jun 10, 2002 at 20:50 UTC