gpt4 book ai didi

lwp - 不带命名参数的 REST HTTP DELETE

转载 作者:行者123 更新时间:2023-12-02 21:54:10 24 4
gpt4 key购买 nike

我想做:

 curl -X DELETE -d '{"name":"flowx"}' 'http://somewhere/wm/staticflowentrypusher/json'

在 Perl 中:

 my $browser = LWP::UserAgent->new;
my $url = 'http://somewhere/wm/staticflowentrypusher/json';
$browser->delete($url, '{"name":"flowx"}');

但我得到:

 Illegal field name '{"name":"flowx"}' at /home/user/perl5/lib/perl5/HTTP/Request/Common.pm line 115

最佳答案

LWP::UserAgent::delete() 中的参数用于创建 header 而不是内容。使用 HTTP:Request 来实现:

my $browser = LWP::UserAgent->new;
my $url = 'http://somewhere/wm/staticflowentrypusher/json';

my $req = HTTP::Request->new(DELETE => $url);

$req->content('{"name":"flowx"}');
my $response = $browser->request($req);

say $response->content;

关于lwp - 不带命名参数的 REST HTTP DELETE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18056216/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com