On Mon, Mar 04, 2002 at 09:05:45PM -0800, open source devel company wrote:
[snip]
> The script that doesn't output the required search
> results ...funny till yesterday it never even output
> the html which it does now ...prompting me to use
> LWP::Debug..but today it outputs some html but not the
> desired results..maybe Im passing the contents wrongly
> .....

The problem is you're passing the query string data in
the content of the request.  For a GET request it needs
to be part of the URL. 

> $content = "hl=en&q=programmer";
>   $req = new HTTP::Request 'GET' =>
> 'http://www.google.com/search';
>   $req->header('Accept' => 'text/html');
> $req->content($content);

Try this:

#!/usr/bin/perl -w

use strict;
use LWP::UserAgent;

my $ua = new LWP::UserAgent;
$ua->agent("$0/0.1 " . $ua->agent);
my $req = HTTP::Request->new(
  GET => 'http://www.google.com/search?hl=en&q=programmer',
);
my $res = $ua->request($req);

# check the outcome
if ($res->is_success) {
  print $res->content;
} else {
  die "Error: ", $res->status_line;
}

Maurice

Reply via email to