[英]How do I change the order of HTTP request headers sent by Perl's LWP?
For a test i need to do a get requets to a website - unfortunatly when using perl lwp the "connection" appears in the header b4 the host. 对于测试,我需要对网站进行一次获取 - 不幸的是,当使用perl lwp时,“连接”出现在主机的标题b4中。 As a result the request gets filtered by the web application firewall. 结果,请求被Web应用程序防火墙过滤。 All i need is to remove or move down the connection line in the header. 我只需要删除或下移标题中的连接线。 When i do the requets with my script: 当我用我的脚本执行requets时:
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?...');
....
The header looks like this: 标题看起来像这样:
GET /test.html?... HTTP/1.1
Connection: close
Host: www.test.com
User-Agent: whateva
Cookie: XXXX
BUT it should look like this to work (conenction comes after host): 但它应该看起来像这样工作(conenction来自主机):
GET /test.html?... HTTP/1.1
Host: www.test.com
Connection: close
User-Agent: whateva
Cookie: XXXX
How do i get rid of that connection line in LWP? 如何摆脱LWP中的连接线? I just need to re-oder it....Its not that it needs to be completly removed; 我只需要重新编写它......它不是需要完全删除它; I am happy to add it later in there again as 我很高兴再次在那里添加它作为
# $userAgent->default_header ("Connection" => "keep-alive");..
Thx a lot in advance! 很多提前!
To work around the bug in your firewall*, change 要解决防火墙*中的错误,请进行更改
return _bytes(join($CRLF, "$method $uri HTTP/$ver", @h2, @h, "", $content));
in Net/HTTP.pm
to 在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));
* — According to the HTTP/1.1 spec, RFC 2616, "The order in which header fields with differing field names are received is not significant." * - 根据HTTP / 1.1规范RFC 2616,“接收到具有不同字段名称的头字段的顺序并不重要。”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.