perl6 Net::HTTP 发送任意 url 请求例子

只做个笔记, 用 HTTP::UserAgent 的话, url 中有特殊点的符号会请求不了, 用 Net::HTTP 能很好的发送请求。

use Net::HTTP::GET;
my $url     = Net::HTTP::URL.new("http://localhost/%20%0a%23%0aadmin");
my $request = Net::HTTP::Request.new(:$url, :method<GET>, header => :cookie<1>);

say $request.Str;
my $rp = Net::HTTP::Transport.new();
my $html = $rp.round-trip($request);
say $html.body.decode('utf-8')

$html 返回的是 Buf 数据, 记得decode。

原文地址:https://www.cnblogs.com/perl6/p/8209412.html