我使用WWW::Mechanize
與運行其自己的基於SSLv3的Web服務器的硬件進行HTTPS連接。WWW ::使用SSL的機械化工作,但響應速度慢
我的代碼有效,但對get(),submit()和click()的響應慢慢回來,範圍從6秒到12秒。
存在導致服務器的IP地址與其在證書中使用的IP地址不同的配置問題。出於這個原因,我暫時忽略了主機名驗證。
這可能是WWW :: Mechanize速度慢的原因。但是,使用常規Web瀏覽器執行相同的功能時沒有任何緩慢。我在Solaris 10(sparc)上運行,使用Perl 5.20.1和OpenSSL 0.7.9d。當與其他服務器進行正常的HTTP連接時,機械化運行速度很快。
我也嘗試了所有的代理別名。沒提升。
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";
UPDATE:
我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:
這裏是在我與斯蒂芬的談話中說明的更改我的工作腳本。保持活力是解決方案。
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();
感謝您收到有關SSL_verifycn的提示。我會試一試。你是對的。它是0.9.7d,這是一個不尋常的配置。如果我升級OpenSSL,我想我將不得不更新一些Perl模塊,比如Net :: SSLeay。我沒有Crypt :: SSLeay,我不認爲我使用的是WWW :: Mechanize。我會盡快發佈我的結果。 – MikeU 2014-10-28 22:18:10
WWW :: Mechanize使用LWP :: UserAgent,它自6.0版默認使用IO :: Socket :: SSL。 IO :: Socket :: SSL本身使用Net :: SSLeay。 Crypt :: SSLeay在6.0之前的LWP版本中使用。由於您明確禁用了主機名的檢查,因此您必須使用IO :: Socket :: SSL後端,因爲Crypt:SSLeay無論如何都不檢查主機名。所以它應該足以重新編譯Net :: SSLeay。 – 2014-10-29 05:31:14
我更新到OpenSSL 1.0.1j,並將結果添加到我上面的原始帖子中。 – MikeU 2014-10-29 22:27:53