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

I have inherited a CGI that does $content = get($URL) to grab another site's page. I now need to modify this script to invoke a CGI on another site, ( a search request actually) e.g. http://searchservice/cgi/search?q=somestring For the life of me I can't remember how to do this as it's 3 years since I was into CGI. Any help appreciated..

Replies are listed 'Best First'.
Getting results from another CGI
by howard40 (Beadle) on Mar 01, 2001 at 07:36 UTC
    Taken (and modified) from the LWP documentation at (www.perldoc.com)

    POST a search query to lycos, and get the results:
    # Create a user agent object use LWP::UserAgent; $ua = new LWP::UserAgent; $ua->agent("AgentName/0.1 " . $ua->agent); # Create a request my $req = new HTTP::Request GET => 'http://www.lycos.com/srch/?lpv=1&loc=searchhp&query=Something'; $req->content_type('application/x-www-form-urlencoded'); $req->content('match=www&errors=0'); # 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) { print $res->content; } else { print "Bad luck this time\n"; }
Re: My CGI to your CGI
by eg (Friar) on Mar 01, 2001 at 05:45 UTC

    The easiest thing to do would be to use CGI.pm and generate a redirect:

    print $cgi->redirect("http://searchservice/cgi/search?q=something");
      ahh,Thanks, but I didn't tell you the rest of the story :-) I need to grab the response for some post processing..
        The $content = get($URL) should work even with another cgi script, since your using the searchstring is part of the URL.
        Life? What's a life?