gpt4 book ai didi

Perl UserAgent 无法连接到 TLS1.2 服务器

转载 作者:太空宇宙 更新时间:2023-11-03 13:12:05 25 4
gpt4 key购买 nike

Perl version is = 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,我收到错误消息 -

"Can't connect to 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

求助! -艾迪

最佳答案

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 握手发送的内容,因此服务器关闭了连接。服务器这样做的原因尚不清楚,但您可能会在服务器端找到错误消息。

Same HTTP call through curl works fine.

如果这确实是一个 HTTP 调用(即没有 HTTPS),那么您使用 curl 执行的操作比您的问题是服务器期望没有 SSL 的 HTTP 但您的 LWP 代码使用 HTTP 和 SSL (HTTPS)。但是,如果使用 curl 的 HTTPS 调用成功,那么您可以通过捕获使用 curl 的成功调用和使用 LWP 的不成功调用的数据包来调试问题,并比较握手。

I have tried various SSL_versions string tlsv12, tslv1.2, TSLv1, TLSv12, TLS, etc. to no avail.

对于当前版本的 IO::Socket::SSL,它将接受 TLSv12 和 TLSv1_2 用于 TLS 1.2 和 TLSv1 用于 TLS 1.*,大小写无关紧要。仅指定“TLS”将导致 IO::Socket::SSL 崩溃。旧版本的 IO::Socket::SSL(2012 年 1.70 之前的版本)只是忽略了无效设置。另请参阅描述设置的文档。

关于Perl UserAgent 无法连接到 TLS1.2 服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32017258/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com