gpt4 book ai didi

perl - 如何使用 HTTP 请求发布内容 (Perl)

转载 作者:可可西里 更新时间:2023-11-01 15:10:20 31 4
gpt4 key购买 nike

use LWP::UserAgent;
use Data::Dumper;

my $ua = new LWP::UserAgent;
$ua->agent("AgentName/0.1 " . $ua->agent);
my $req = new HTTP::Request POST => 'http://example.com';
$req->content('port=8', 'target=64'); #problem
my $res = $ua->request($req);

print Dumper($res->content);

如何使用 $req->content 发送多条内容? $req->content 需要什么样的数据?

它只发送最后一个。

编辑:

发现如果我将其格式化为“port=8&target=64”,它就可以工作。有没有更好的办法?

最佳答案

my $ua      = LWP::UserAgent->new(); 
my $request = POST( $url, [ 'port' => 8, 'target' => 64 ] );
my $content = $ua->request($request)->as_string();

关于perl - 如何使用 HTTP 请求发布内容 (Perl),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11264470/

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