我无法为https网站使用perl模块LWP :: Parallel :: UserAgent。以下是我使用的代码:
#!的/ usr / bin中/ perl的
使用LWP :: Parallel :: UserAgent qw(:CALLBACK);使用HTTP :: Request;
我的…
从您的代码:
$pua->nonblock('true');
在查看LWP :: Parallel :: UserAgent的代码时,看起来对HTTPS的非阻塞支持完全被破坏了: https 支持是在LWP :: Parallel :: Protocol :: https中实现的,它派生自LWP :: Parallel :: Protocol :: http for 做实际的连接 。相关代码 sub _connect :
https
103 unless ($nonblock) { 104 # perform good ol' blocking behavior 105 # 106 # this method inherited from LWP::Protocol::http 107 $socket = $self->_new_socket($host, $port, $timeout); 108 # currently empty function in LWP::Protocol::http 109 # $self->_check_sock($request, $socket); 110 } else { 111 # new non-blocking behavior ... 116 $socket = 117 IO::Socket::INET->new(Proto => 'tcp', # Timeout => $timeout, 118 $self->_extra_sock_opts ($host, $port));
可以看到,对于(默认)阻塞情况,代码使用的功能 LWP::Protocol::http ,但对于它直接使用的非阻塞情况 IO::Socket::INET - 并不是 IO::Socket::SSL 用于HTTPS。但是LWP :: Protocol :: http(稍后使用)实际上需要SSL套接字并尝试调用 get_cipher 在上面。这会导致您看到的错误:
LWP::Protocol::http
IO::Socket::INET
IO::Socket::SSL
get_cipher
无法通过/usr/share/perl5/LWP/Protocol/https.pm第119行中的包“IO :: Socket :: INET”找到对象方法“get_cipher”
当不使用非阻塞支持时,代码似乎可以工作。
至于HTTPS一般在这个模块中看到 README.SSL :
** DISCLAIMER: https support is pretty buggy as of now. i haven't ** ** had time to test much of it, so feel free to see if it works ** ** for you, but don't expect it to :-)
换句话说:您应该使用不同的模块来获得对HTTPS的可靠支持。