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。

posted on 2018-01-06 02:34  Perl6  阅读(297)  评论(0编辑  收藏  举报

导航