Search code examples
perllwp-useragent

LWP::UserAgent post method not return value


Just copy this code from perl cook book 2nd ed pp. 796

it returns: 400 URL must be absolute.

What's wrong with this code?

#!"c:\strawberry\perl\bin\perl.exe" -w

use 5.006;
use strict;
use LWP::Simple;
use LWP::UserAgent;

my $ua = LWP::UserAgent->new();
my $resp = $ua->post("www.amazon.com/exec/obidos/search-handle-form",
                     { "url"             => "index-books",
                       "field-keywords"  => "perl"}
);
my $content = $resp->content;

print $content, "\n";

Solution

  • You forgot the http:// on the front of the URL

    Well, presumably http://, it might be https://, ftp://, etc, etc.