Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

LWP post

by prc_perl_c_c++_java (Initiate)
on Feb 23, 2005 at 23:58 UTC ( [id://433909]=perlquestion: print w/replies, xml ) Need Help??

prc_perl_c_c++_java has asked for the wisdom of the Perl Monks concerning the following question:

Sorry to ask such a simple question but I deal primarily with other languages, and I coudln't find the answer newhere else. A friend of mine mentioned a subroutine called post which sends data to another address He was unable to tell me however teh syntax and whether it was in LWP::Simple or not any answers?

Replies are listed 'Best First'.
Re: LWP post
by esskar (Deacon) on Feb 24, 2005 at 00:09 UTC
    check LWP::UserAgent
    an example:
    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'

      Let me know what do do the follwoing :

      my $ua->agent("MyApp/0.1 ");

      and what is MyApp/0.1

        (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.

Re: LWP post
by borisz (Canon) on Feb 24, 2005 at 01:29 UTC
    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;
    Boris
Re: LWP post
by hsinclai (Deacon) on Feb 24, 2005 at 01:09 UTC
    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
      is it really a binary? on windows maschine it's just another perl script (same for get and head)
        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!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://433909]
Approved by Tanktalus
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2024-03-28 21:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found