4

How can I make a HTTP PUT request in Perl that contains application/x-www-form-urlencoded data?

This is an equivalent POST request that works:

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

How would this be done as a PUT request? There is no put method in LWP and the PUT function in HTTP::Request::Common does not take form data.

For a discussion if a PUT request with form data is allowed, see Can HTTP PUT request have application/x-www-form-urlencoded as the Content-Type?

This is an example of a PUT request, but it does not contain code to enclose form data: How to make a HTTP PUT request using LWP?

Community
  • 1
  • 1
Fabian
  • 5,476
  • 4
  • 35
  • 46

1 Answers1

7

Just make POST-request and change its method to PUT:

use HTTP::Request::Common;

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

$req->method('PUT');

say($req->as_string);
Denis Ibaev
  • 2,470
  • 23
  • 29