Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Perl发布到带有请求头的网页_Perl_Http Headers_User Agent - Fatal编程技术网

使用Perl发布到带有请求头的网页

使用Perl发布到带有请求头的网页,perl,http-headers,user-agent,Perl,Http Headers,User Agent,我试图用Perl将数据发布到页面,但该页面也需要标题。我如何发布标题和发送标题(cookies、用户代理等) 我尝试使用,但我不知道如何发送标题,即使我可以发布到页面 关于这个话题还有一件事。当我在该页面上发布并打印响应内容时,我可以看到html,除了应该显示的数字之外。尝试这样做: use LWP::UserAgent; use HTTP::Request; my $userAgent = LWP::UserAgent->new(); my $request = HTTP::Reque

我试图用Perl将数据发布到页面,但该页面也需要标题。我如何发布标题和发送标题(cookies、用户代理等)

我尝试使用,但我不知道如何发送标题,即使我可以发布到页面

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

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;
}
尝试这样做:

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;
}

谢谢,我将尝试一下。$userAgent未定义。请修复响应。谢谢,我将尝试一下。$userAgent未定义。请修改响应。