Perl版本= v5.12.4
LWP :: UserAgent-> VERSION = 6.03
#....
# Setup HTTP request
my $req = HTTP::Request->new();
$req->method($cmd);
$req->uri($uri);
$req->header('content-type' => 'application/json');
$req->header('Accept' => 'application/json');
# Setup the call
my $ua = LWP::UserAgent->new(ssl_opts => { verify_hostname => 0,
SSL_version => 'tlsv12' });
$ua->timeout(60);
# Do the call
my $resp = $ua->request($req);
# ....
http代码始终为500
,我收到错误消息 -
"无法连接到10.0.0.1:443"。
我尝试了各种SSL_versions字符串tlsv12,tslv1.2,TSLv1,TLSv12,TLS等无济于事。我知道服务器需要TLS 1.2。通过curl进行相同的HTTP调用工作正常。
其他调试输出..
Perl -MIO::Socket::SSL=debug4 powervc_cli.pl -O
DEBUG: .../IO/Socket/SSL.pm:193: set domain to 2
DEBUG: .../IO/Socket/SSL.pm:1545: new ctx 140528264056208
DEBUG: .../IO/Socket/SSL.pm:334: socket not yet connected
DEBUG: .../IO/Socket/SSL.pm:336: socket connected
DEBUG: .../IO/Socket/SSL.pm:349: ssl handshake not started
DEBUG: .../IO/Socket/SSL.pm:379: set socket to non-blocking to enforce timeout=60
DEBUG: .../IO/Socket/SSL.pm:392: Net::SSLeay::connect -> -1
DEBUG: .../IO/Socket/SSL.pm:402: ssl handshake in progress
DEBUG: .../IO/Socket/SSL.pm:412: waiting for fd to become ready: SSL wants a read first
DEBUG: .../IO/Socket/SSL.pm:432: socket ready, retrying connect
DEBUG: .../IO/Socket/SSL.pm:392: Net::SSLeay::connect -> 0
DEBUG: .../IO/Socket/SSL.pm:440: connection failed - connect returned 0
DEBUG: .../IO/Socket/SSL.pm:1276: SSL connect attempt failed because of handshake problemserror:00000000:lib(0):func(0):reason(0)
DEBUG: .../IO/Socket/SSL.pm:1276: IO::Socket::INET6 configuration failederror:00000000:lib(0):func(0):reason(0)
DEBUG: .../IO/Socket/SSL.pm:1582: free ctx 140528264056208 open=140528264056208
DEBUG: .../IO/Socket/SSL.pm:1590: OK free ctx 140528264056208
请帮忙! -Eddie
答案 0 :(得分:3)
DEBUG: .../IO/Socket/SSL.pm:392: Net::SSLeay::connect -> 0 DEBUG: .../IO/Socket/SSL.pm:440: connection failed - connect returned 0 DEBUG: .../IO/Socket/SSL.pm:1276: SSL connect attempt failed because of handshake problemserror:00000000:lib(0):func(0):reason(0)
这看起来像服务器不喜欢客户端作为SSL握手发送的内容,因此服务器关闭了连接。为什么服务器这样做不明确,但您可能会在服务器端找到错误消息。
通过curl进行相同的HTTP调用工作正常。
如果这实际上是一个HTTP调用(即没有HTTPS),那么你使用curl比你的问题是服务器需要HTTP没有SSL,但你的LWP代码使用HTTP和SSL(HTTPS)。但是如果使用curl的HTTPS调用成功,则可以通过使用curl进行成功调用的数据包捕获以及使用LWP失败来调试问题,并比较握手。
我尝试过各种SSL_versions字符串tlsv12,tslv1.2,TSLv1,TLSv12,TLS等无济于事。
对于当前版本的IO :: Socket :: SSL,它将接受TLS 1.2的TLSv12和TLSv1_2以及TLS 1的TLSv1。*,大小写无关紧要。仅指定“TLS”将导致IO :: Socket :: SSL出现问题。较早版本的IO :: Socket :: SSL(2012年版本1.70之前)只是忽略了无效设置。另请参阅描述设置的文档。