错误:500 无法连接到 example.com:443(证书验证失败) [英] Error: 500 Can't connect to example.com:443 (certificate verify failed)
问题描述
我收到那个错误.这是我的代码.
使用 LWP::UserAgent;使用 HTTP::Request::Common qw(POST);使用 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',内容 =>['用户名'='111','密码'='2222','虚拟主机'='标准']);$req->header('Cookie' =>q(TIN=287000; LastMRH_Session=439960f5; MRHSession=78c9c47291c1fcedae166121439960f5));$resp=$UA->request($req);if(($resp->code()>=200)&&($resp->code()<400)){打印 $resp->decoded_content;}别的{打印错误:".$resp->status_line.\n";}
问题是我没有真正的证书可以提供,因为该站点处于开发阶段,并且使用了本地主机的证书......浏览器不识别它.
有没有办法绕过验证??并避免错误?
更新:
我稍微改变了我的代码.添加了另一个库并添加了此功能:
使用 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;
I get that error. Here is my code.
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";
}
The problem is that I have no real certificate to provide, because the site is in development stages, and a certificate of the localhost is used... the browsers don't recognize it.
Is there a way to bypass the verification?? and avoid the error?
UPDATE:
I changed my code a bit. Added another library and added this function:
use CACertOrg::CA;
$ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = 0;
$UA->ssl_opts(
verify_hostnames => 0,
SSL_ca_file => CACertOrg::CA::SSL_ca_file()
);
Now I get this:
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.
at C:/Perl/lib/LWP/Protocol/http.pm line 31.
So I changed the options to this:
$UA->ssl_opts(
SSL_verify_mode => 'SSL_VERIFY_NONE',
verify_hostnames => 0,
SSL_ca_file => CACertOrg::CA::SSL_ca_file()
);
I get nothing printed... I don't get an error, though. Is it a good sign?
You need to add this line after use ..
part:
$ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = 0;
这篇关于错误:500 无法连接到 example.com:443(证书验证失败)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!