perl – 错误:500无法连接到example.com:443(证书验证失败)
我收到了这个错误.这是我的代码.
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() ); 现在我明白了:
在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; (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |