use strict;
use LWP::UserAgent;
my $ua = LWP::UserAgent->new;
$ua->agent("MyApp/0.1 ");
my $req = HTTP::Request->new(POST => 'http://search.cpan.org/search');
$req->content_type('application/x-www-form-urlencoded');
$req->content('query=libwww-perl&mode=dist');
my $res = $ua->request($req);
if ($res->is_success) {
print $res->content;
}
else {
print $res->status_line, "\n";
}
Update: Fixed the 'my' | [reply] [Watch: Dir/Any] [d/l] |
my $ua->agent("MyApp/0.1 ");
and what is MyApp/0.1
| [reply] [Watch: Dir/Any] [d/l] [select] |
(The my shouldn't be there.)
The line is optional. It tells LWP what to put in the User-Agent field of the HTTP request, which is pretty much a free-format field. The default is indicates LWP is being used and which version of LWP is being used.
Some web servers use this to return content specific for the browser identified by the string. Some web servers log this to monitor which browsers its users use.
| [reply] [Watch: Dir/Any] [d/l] |
Perhaps this POST function s is what you searched for:
use LWP::UserAgent;
use HTTP::Request::Common;
my $ua = LWP::UserAgent->new;
my $res = $ua->request( POST "http://search.cpan.org/search",
[ query => 'libwww-perl', mode => 'dist' ] );
print $res->content if $res->is_success;
| [reply] [Watch: Dir/Any] [d/l] |
Aside from the LWP modules, the perl libwww package includes (everywhere I've seen, at least on unix) the very useful binary executables POST, GET, and HEAD, which can be used from the command line - maybe your friend was referring to the POST binary?
It does neat things:
machine# POST
Usage: POST [-options] <url>...
-m <method> use method for the request (default is 'POST')
-f make request even if POST believes method is illegal
-b <base> Use the specified URL as base
-t <timeout> Set timeout value
-i <time> Set the If-Modified-Since header on the request
-c <conttype> use this content-type for POST, PUT, CHECKIN
-a Use text mode for content I/O
-p <proxyurl> use this as a proxy
-P don't load proxy settings from environment
-H <header> send this HTTP header (you can specify several)
-u Display method and URL before any response
-U Display request headers (implies -u)
-s Display response status code
-S Display response status chain
-e Display response headers
-d Do not display content
-o <format> Process HTML content in various ways
-v Show program version
-h Print this message
-x Extra debugging output
| [reply] [Watch: Dir/Any] [d/l] |
is it really a binary? on windows maschine it's just another perl script (same for get and head)
| [reply] [Watch: Dir/Any] |
It is a script - you're right - don't know why I remembered it as binary - thanks for setting me straight - it uses LWP::UserAgent among other things in there!
| [reply] [Watch: Dir/Any] |