develooper Front page | perl.libwww | Postings from December 2003

[PATCH] LWP.pm example

From:
peter
Date:
December 30, 2003 08:57
Subject:
[PATCH] LWP.pm example
Message ID:
20031230163335.36099.qmail@onion.perl.org
The first example in LWP.pm shows a POST request whose
content and headers are constructed manually.  BackPAN
tells me this examplee preceded the introduction of
HTTP::Request::Common, and I see on clpmisc that some
people think this manual method is the best way to do
a POST because of this example.  Therefore, this patch:

--- LWP.pm.orig 2003-12-30 08:24:29.000000000 -0800
+++ LWP.pm      2003-12-30 08:28:04.000000000 -0800
@@ -302,9 +302,9 @@
   $ua->agent("MyApp/0.1 ");
 
   # Create a request
-  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');
+  use HTTP::Request::Common;
+  my $req = POST 'http://search.cpan.org/search',
+                 [ query => 'libwww-perl', mode => 'dist' ];
 
   # Pass request to the user agent and get a response back
   my $res = $ua->request($req);

-- 
Peter Scott
http://www.perldebugged.com/
*** NEW *** http//www.perlmedic.com/



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About