Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a HTTP PUT request using LWP?

I'm trying to change this request to a HTTP PUT request, any idea how ?

my $request = LWP::UserAgent->new; 
my $response = 
        $request->get($url, "apikey", $apiKey, "requestDate", $requestDate);
like image 929
Steve Avatar asked Dec 11 '11 10:12

Steve


3 Answers

You should use HTTP::Request:

use LWP::UserAgent;
use HTTP::Request;

my $ua = LWP::UserAgent->new;
my $req = HTTP::Request->new("PUT", $url); 

my $res = $ua->request($req);
like image 91
gangabass Avatar answered Nov 08 '22 17:11

gangabass


As of 6.04, LWP::UserAgent has a put helper, so you can now do:

$ua->put( $url )
like image 43
andrewrjones Avatar answered Nov 08 '22 17:11

andrewrjones


PUT is HTTP::Request::Common. You can build the request first and pass it into user agent.

use HTTP::Request::Common;
use LWP;

$agent    = LWP::UserAgent->new;
$request  = HTTP::Request::Common::PUT($url, "apikey", $apiKey, "requestDate", $requestDate); 
$response = $agent->request($request);
like image 2
sabertiger Avatar answered Nov 08 '22 17:11

sabertiger