How to make a HTTP PUT request using LWP?

烈酒焚心 提交于 2019-12-07 03:58:50

问题


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

回答1:


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



回答2:


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

$ua->put( $url )



回答3:


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


来源:https://stackoverflow.com/questions/8463187/how-to-make-a-http-put-request-using-lwp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!