我使用WWW::Mechanize
与运行自己的基于SSLv3的网络服务器的硬件进行HTTPS连接。
我的代码有效但是对get(),submit()和click()的响应缓慢回来,范围从6到12秒。
配置问题导致服务器的IP地址与其证书中使用的IP地址不同。出于这个原因,我暂时忽略了主机名验证。
这可能是WWW :: Mechanize速度慢的原因。但是,使用常规Web浏览器执行相同功能时,速度并不慢。我在Solaris 10(sparc)上运行,使用Perl 5.20.1和OpenSSL 0.7.9d。当与其他服务器进行正常的HTTP连接时,Mechanize会快速运行。
我也尝试了所有代理别名。没有得到改善。
use WWW::Mechanize;
$ENV{HTTPS_VERSION} = 3; # Try SSLv3 first
$ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = 0; # Ignore verification
my $agent = WWW::Mechanize->new( autocheck => 1 );
$agent->get($https_url);
$agent->credentials( $username, $password );
$agent->get($status_url);
print "$agent->{content}\n";
$agent->form_number(2);
$agent->click();
print "$agent->{content}\n";
更新
我将OpenSSL更新为1.0.1j并重新编译Net :: SSLeay 1.66。我还将IO :: Socket :: SSL更新为2.002。我仍然看到了同样的行为。
然后我重新编译了LWP :: Protocol :: https 6.0.6和WWW :: Mechanize 1.73以获得良好的衡量标准。同样的行为。
我在帖子中添加了use IO::Socket::SSL qw(debug3);
。我可以看到调试输出有6秒的延迟。
Fetching initial page...
DEBUG: .../IO/Socket/SSL.pm:2537: new ctx 11476520
DEBUG: .../IO/Socket/SSL.pm:529: socket not yet connected
DEBUG: .../IO/Socket/SSL.pm:531: socket connected
DEBUG: .../IO/Socket/SSL.pm:553: ssl handshake not started
DEBUG: .../IO/Socket/SSL.pm:589: not using SNI because hostname is unknown
DEBUG: .../IO/Socket/SSL.pm:640: set socket to non-blocking to enforce timeout=180
DEBUG: .../IO/Socket/SSL.pm:653: Net::SSLeay::connect -> -1
DEBUG: .../IO/Socket/SSL.pm:663: ssl handshake in progress
DEBUG: .../IO/Socket/SSL.pm:673: waiting for fd to become ready: SSL wants a read first
DEBUG: .../IO/Socket/SSL.pm:693: socket ready, retrying connect
DEBUG: .../IO/Socket/SSL.pm:653: Net::SSLeay::connect -> -1
DEBUG: .../IO/Socket/SSL.pm:663: ssl handshake in progress
DEBUG: .../IO/Socket/SSL.pm:673: waiting for fd to become ready: SSL wants a read first
# >>> There's a 6 second delay here <<<
DEBUG: .../IO/Socket/SSL.pm:693: socket ready, retrying connect
DEBUG: .../IO/Socket/SSL.pm:653: Net::SSLeay::connect -> -1
DEBUG: .../IO/Socket/SSL.pm:708: ssl handshake done
DEBUG: .../IO/Socket/SSL.pm:2570: free ctx 11476520 open=11476520
DEBUG: .../IO/Socket/SSL.pm:2582: OK free ctx 11476520
Credentials...
Fetching status page...
DEBUG: .../IO/Socket/SSL.pm:2537: new ctx 11476520
DEBUG: .../IO/Socket/SSL.pm:529: socket not yet connected
DEBUG: .../IO/Socket/SSL.pm:531: socket connected
DEBUG: .../IO/Socket/SSL.pm:553: ssl handshake not started
DEBUG: .../IO/Socket/SSL.pm:589: not using SNI because hostname is unknown
DEBUG: .../IO/Socket/SSL.pm:640: set socket to non-blocking to enforce timeout=180
DEBUG: .../IO/Socket/SSL.pm:653: Net::SSLeay::connect -> -1
DEBUG: .../IO/Socket/SSL.pm:663: ssl handshake in progress
DEBUG: .../IO/Socket/SSL.pm:673: waiting for fd to become ready: SSL wants a read first
DEBUG: .../IO/Socket/SSL.pm:693: socket ready, retrying connect
DEBUG: .../IO/Socket/SSL.pm:653: Net::SSLeay::connect -> -1
DEBUG: .../IO/Socket/SSL.pm:663: ssl handshake in progress
DEBUG: .../IO/Socket/SSL.pm:673: waiting for fd to become ready: SSL wants a read first
# >>> Another 6 second delay <<<
DEBUG: .../IO/Socket/SSL.pm:693: socket ready, retrying connect
DEBUG: .../IO/Socket/SSL.pm:653: Net::SSLeay::connect -> -1
DEBUG: .../IO/Socket/SSL.pm:708: ssl handshake done
DEBUG: .../IO/Socket/SSL.pm:2570: free ctx 11476520 open=11476520
DEBUG: .../IO/Socket/SSL.pm:2582: OK free ctx 11476520
DEBUG: .../IO/Socket/SSL.pm:2537: new ctx 11476520
DEBUG: .../IO/Socket/SSL.pm:529: socket not yet connected
DEBUG: .../IO/Socket/SSL.pm:531: socket connected
DEBUG: .../IO/Socket/SSL.pm:553: ssl handshake not started
DEBUG: .../IO/Socket/SSL.pm:589: not using SNI because hostname is unknown
DEBUG: .../IO/Socket/SSL.pm:640: set socket to non-blocking to enforce timeout=180
DEBUG: .../IO/Socket/SSL.pm:653: Net::SSLeay::connect -> -1
DEBUG: .../IO/Socket/SSL.pm:663: ssl handshake in progress
DEBUG: .../IO/Socket/SSL.pm:673: waiting for fd to become ready: SSL wants a read first
DEBUG: .../IO/Socket/SSL.pm:693: socket ready, retrying connect
DEBUG: .../IO/Socket/SSL.pm:653: Net::SSLeay::connect -> -1
DEBUG: .../IO/Socket/SSL.pm:663: ssl handshake in progress
DEBUG: .../IO/Socket/SSL.pm:673: waiting for fd to become ready: SSL wants a read first
# >>> Another 6 second delay <<<
DEBUG: .../IO/Socket/SSL.pm:693: socket ready, retrying connect
DEBUG: .../IO/Socket/SSL.pm:653: Net::SSLeay::connect -> -1
DEBUG: .../IO/Socket/SSL.pm:708: ssl handshake done
DEBUG: .../IO/Socket/SSL.pm:2570: free ctx 11476520 open=11476520
DEBUG: .../IO/Socket/SSL.pm:2582: OK free ctx 11476520
Submitting form...
# Repeat of behavior when fetching the initial page, except ctx is 12700768
SOLUTION:
这是我的工作脚本,其中包含与Steffen对话中描述的更改。保持活力是解决方案。
use WWW::Mechanize;
use IO::Socket::SSL qw(debug3); # Turn on level 3 debug
use LWP::ConnCache;
$ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = 0; # Ignore verification
my $agent = WWW::Mechanize->new(autocheck => 1);
$agent->conn_cache(LWP::ConnCache->new); # Enable keep-alive
$agent->get($https_url);
$agent->credentials($username, $password);
$agent->get($status_url);
$agent->form_number(2);
$agent->click();
答案 0 :(得分:3)
配置问题导致服务器的IP地址与其证书中使用的IP地址不同。出于这个原因,我暂时忽略了主机名验证。
最好使用IO :: Socket :: SSL的SSL_verifycn_name设置来定义您希望在证书中使用的名称。
这可能是WWW :: Mechanize速度慢的原因。
可能不是,因为你只是禁用支票。禁用不会使速度变慢,但启用也不会使速度变慢,因为这些检查速度很快,并且不需要任何额外的网络活动。
我在Solaris 10(sparc)上运行,使用Perl 5.20.1和OpenSSL 0.7.9d。
我怀疑你使用0.7.9d,你可能意味着0.9.7d。它仍然是一个非常不寻常的配置,即使用具有10年版OpenSSL的现代Perl。我建议您使用当前版本,也许你的问题就会消失。
但是,使用常规Web浏览器执行相同功能时,速度并不慢。
目前的浏览器使用现代TLS堆栈,它具有更高效的密码,会话恢复等。再次尝试使用最新版本的OpenSSL。