加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

perl – 错误:500无法连接到example.com:443(证书验证失败)

发布时间:2020-12-15 21:48:27 所属栏目:大数据 来源:网络整理
导读:我收到了这个错误.这是我的代码. 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 = Mozil
我收到了这个错误.这是我的代码.
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";
}

问题是我没有提供真正的证书,因为该站点处于开发阶段,并且使用了localhost的证书……浏览器不识别它.

有没有办法绕过验证?并避免错误?

更新:

我改变了我的代码.添加了另一个库并添加了此功能:

use CACertOrg::CA;

$ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = 0;

$UA->ssl_opts(
    verify_hostnames => 0,SSL_ca_file      => CACertOrg::CA::SSL_ca_file()
);

现在我明白了:


Using the default of SSL_verify_mode of SSL_VERIFY_NONE for client
is deprecated! Please set SSL_verify_mode to SSL_VERIFY_PEER
together with SSL_ca_file|SSL_ca_path for verification.
If you really don’t want to verify the certificate and keep the
connection open to Man-In-The-Middle attacks please set
SSL_verify_mode explicitly to SSL_VERIFY_NONE in your application.


在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()
);

我没有得到任何打印..虽然我没有得到错误..这是一个好兆头吗?

解决方法

您需要在使用后添加此行..部分:
$ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = 0;

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读