2011-12-11 49 views
6

我想改變這個請求到一個HTTP PUT請求,任何想法如何?如何使用LWP創建HTTP PUT請求?

my $request = LWP::UserAgent->new; 
my $response = 
     $request->get($url, "apikey", $apiKey, "requestDate", $requestDate); 

回答

10

您應該使用HTTP ::請求:

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

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

my $res = $ua->request($req); 
+0

THX我已經想通了! – Steve

2

PUT是HTTP ::支持::常見。您可以先構建請求並將其傳遞給用戶代理。

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

截至6.04,LWP::UserAgentput幫手,所以你現在可以做的:

$ua->put($url)