How to make a HTTP PUT request using LWP?

2019-06-20 05:23发布

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);

3条回答
甜甜的少女心
2楼-- · 2019-06-20 05:48

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);
查看更多
贼婆χ
3楼-- · 2019-06-20 06:03

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);
查看更多
闹够了就滚
4楼-- · 2019-06-20 06:04

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

$ua->put( $url )
查看更多
登录 后发表回答