我收到该错误。这是我的代码。错误: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";
}
的万阿英,蒋达清的是,我没有真正的证书来提供,因为该网站正处于发展阶段,本地主机的证书used..the浏览器不承认它。
有没有办法绕过验证?并避免错误?
UPDATE:
我改变了我的代码位。新增另一个库和添加了这个功能:
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()
);
我什么也没得到printed..I没有得到一个错误,但..这是一个好的迹象?
那么它了4年为时已晚,但对于你的问题的更新的一部分,不要”把SSL_VERIFY_NONE放在引号中。这是一个常数,而不是一个字符串。 –