简体   繁体   English

如何更改Perl的LWP发送的HTTP请求标头的顺序?

[英]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.

相关问题 如何使用Perl的LWP提取非标准HTTP头? - How can I extract non-standard HTTP headers using Perl's LWP? Perl LWP:UserAgent如何添加标题? - Perl LWP:UserAgent how to I add headers? 如何使用Perl的LWP登录Web应用程序? - How do I use Perl's LWP to log in to a web application? 如何在tsocks中使用Perl的LWP :: UserAgent GET请求 - How to use Perl's LWP::UserAgent GET request with tsocks 将perl文件参数传递给LWP HTTP请求 - Pass perl file arguments to LWP HTTP request 如何使用Perl的LWP :: Simple发送cookie? - How can I send cookies with Perl's LWP::Simple? 当我使用Perl的REST :: Client发送POST请求,而不使用Perl的LWP :: UserAgent或Python发送POST请求时,为什么会收到“ 405:方法不允许”的信息? - Why do I get “405: Method Not Allowed” when I send a POST request with Perl's REST::Client, but not with Perl's LWP::UserAgent or Python? 使用Perl的LWP时,是否可以根据`Content-Type`中止HTTP请求? - Is it possible to abort a HTTP request depending on the `Content-Type` when using Perl's LWP? 将Vanilla Perl CGI中的请求标头克隆到LWP UserAgent - Clone request headers in Vanilla Perl CGI to LWP UserAgent 使用Perl HTTP :: Response和LWP代理HTTP请求的更好方法? - Better way to proxy an HTTP request using Perl HTTP::Response and LWP?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM