4

如何在 Perl 中发出包含application/x-www-form-urlencoded数据的 HTTP PUT 请求?

这是一个有效的等效 POST 请求:

my $ua       = new LWP::UserAgent;
my $response = $ua->post(
    $url,
    {
        "parameter1" => $value1,
        "parameter2" => $value2
    }
);

这将如何作为 PUT 请求完成?putLWP中没有方法,其中的PUT函数HTTP::Request::Common不接受表单数据。

有关是否允许带有表单数据的 PUT 请求的讨论,请参阅HTTP PUT 请求是否可以将 application/x-www-form-urlencoded 作为 Content-Type?

这是一个 PUT 请求的示例,但它不包含包含表单数据的代码:How to make a HTTP PUT request using LWP?

4

1 回答 1

7

只需发出POST-request 并将其方法更改为PUT

use HTTP::Request::Common;

my $req = POST('http://example.com/', Content => [param => 'value']);

$req->method('PUT');

say($req->as_string);
于 2012-06-26T07:25:52.983 回答