简体   繁体   English

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

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

How can I make a HTTP PUT request in Perl that contains application/x-www-form-urlencoded data? 如何在包含application/x-www-form-urlencoded数据的Perl中发出HTTP PUT请求?

This is an equivalent POST request that works: 这是等效的POST请求,可以正常工作:

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

How would this be done as a PUT request? 作为PUT请求如何完成? There is no put method in LWP and the PUT function in HTTP::Request::Common does not take form data. LWP中没有put方法, HTTP::Request::Common中的PUT函数不采用表格数据。

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? 有关是否允许带有表单数据的PUT请求的讨论,请参见HTTP PUT请求可以将application / x-www-form-urlencode编码为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? 这是一个PUT请求的示例,但其中不包含用于封装表单数据的代码: 如何使用LWP发出HTTP PUT请求?

Just make POST -request and change its method to PUT : 只需执行POST -request并将其方法更改为PUT

use HTTP::Request::Common;

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

$req->method('PUT');

say($req->as_string);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM