1

我正在尝试使用 Perl 将数据发布到页面,但该页面还需要标题。我将如何发布标头和发送标头(cookie、用户代理等)?

我尝试使用LWP::UserAgent,但我无法弄清楚如何发送标题,即使我可以发布到页面。

关于这个话题的另一件事。当我在该页面上发布并打印响应内容时,我可以看到除了应该显示的数字之外的 html。

4

1 回答 1

4

尝试这样做:

use LWP::UserAgent;
use HTTP::Request;

my $userAgent = LWP::UserAgent->new();
my $request = HTTP::Request->new(
    POST => "http://domain.tld/path"
);
$request->content("stuff=foobar");
$request->content_type("application/x-www-form-urlencoded");
my $response = $userAgent->request($request);

if ($response->code == 200) {
    print $response->as_string;
}
else {
   die $response->status_line;
}
于 2013-01-22T01:46:10.630 回答