gpt4 book ai didi

perl - 错误 : 500 Can't connect to example. com:443(证书验证失败)

转载 作者:行者123 更新时间:2023-12-04 13:23:16 25 4
gpt4 key购买 nike

我得到那个错误。这是我的代码。

   use LWP::UserAgent;
use HTTP::Request::Common qw(POST);
use HTTP::Cookies;

$URL="https://example.com/my.plicy";
$UA = LWP::UserAgent->new();
$UA->ssl_opts( verify_hostnames => 0 );
#UA->ssl_opts( SSL_ca_file => Mozilla::CA::SSL_ca_file() );

$req =HTTP::Request::Common::POST("$URL",
Content_type=>'form-data',
Content =>[
'username'=>'111',
'password'=>'2222',
'vhost'=>'standard'
]
);
$req->header('Cookie' =>q(TIN=287000; LastMRH_Session=439960f5; MRHSession=78c9c47291c1fcedae166121439960f5));


$resp=$UA->request($req);

if( ($resp->code() >= 200) && ($resp->code() <400) ) {
print $resp->decoded_content;

}else{
print "Error: ". $resp->status_line. "\n";
}

问题是我没有真正的证书可以提供,因为该站点处于开发阶段,并且使用了本地主机的证书......浏览器无法识别它。
有没有办法绕过验证??并避免错误?
更新:
我稍微改变了我的代码。添加了另一个库并添加了此功能:
use CACertOrg::CA;

$ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = 0;

$UA->ssl_opts(
verify_hostnames => 0,
SSL_ca_file => CACertOrg::CA::SSL_ca_file()
);
现在我明白了:


为客户端使用 SSL_VERIFY_NONE 的默认 SSL_verify_mode
已弃用!请将 SSL_verify_mode 设置为 SSL_VERIFY_PEER
与 SSL_ca_file|SSL_ca_path 一起进行验证。
如果您真的不想验证证书并保留
对中间人攻击开放的连接请设置
在您的应用程序中将 SSL_verify_mode 显式设置为 SSL_VERIFY_NONE。

在 C:/Perl/lib/LWP/Protocol/http.pm 第 31 行。
所以我将选项更改为:
    $UA->ssl_opts(
SSL_verify_mode => 'SSL_VERIFY_NONE',
verify_hostnames => 0,
SSL_ca_file => CACertOrg::CA::SSL_ca_file()
);
我什么也没打印……不过我没有收到错误消息。这是一个好兆头吗?

最佳答案

您需要在 use .. 之后添加这一行部分:

$ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = 0;

关于perl - 错误 : 500 Can't connect to example. com:443(证书验证失败),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19397346/

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