4

对于测试,我需要对网站进行请求 - 不幸的是,当使用 perl lwp 时,“连接”出现在主机 b4 的标题中。结果,请求被 Web 应用程序防火墙过滤。我只需要删除或向下移动标题中的连接线。当我用我的脚本做请求时:

use warnings;
use IO::Socket;
use LWP::UserAgent;
use LWP::Protocol::http;
use HTTP::Request;
my $ua = LWP::UserAgent->new();
push(@LWP::Protocol::http::EXTRA_SOCK_OPTS, SendTE => 0, PeerHTTPVersion => "1.1");
$ua->default_header(Cookie => 'XXX', User-Agent => 'whateva');
my $request = $ua->get('https://www.test.com/test.html?...');
....

标题如下所示:

GET /test.html?... HTTP/1.1
Connection: close
Host: www.test.com
User-Agent: whateva
Cookie: XXXX

但它应该看起来像这样工作(连接在主机之后):

GET /test.html?... HTTP/1.1
Host: www.test.com
Connection: close
User-Agent: whateva
Cookie: XXXX

我如何摆脱 LWP 中的连接线?我只需要重新订购它....并不是说它需要完全删除;我很高兴稍后再将其添加为

# $userAgent->default_header ("Connection" => "keep-alive");..

提前很多!

4

1 回答 1

3

要解决防火墙中的错误*,请更改

return _bytes(join($CRLF, "$method $uri HTTP/$ver", @h2, @h, "", $content));

Net/HTTP.pm

my @h3 = ( @h2, @h );
if (my ($idx) = grep /^Host:/, 0..$#h3) {
    unshift(@h3, splice(@h3, $idx, 1));
}

return _bytes(join($CRLF, "$method $uri HTTP/$ver", @h3, "", $content));



* — 根据 HTTP/1.1 规范,RFC 2616,“接收具有不同字段名称的标头字段的顺序并不重要。”

于 2012-12-10T21:52:46.377 回答