简体   繁体   English

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

[英]Error: 500 Can't connect to example.com:443 (certificate verify failed)

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!不推荐使用 SSL_VERIFY_NONE 的默认 SSL_verify_mode 客户端! Please set SSL_verify_mode to SSL_VERIFY_PEER together with SSL_ca_file|SSL_ca_path for verification.请将 SSL_verify_mode 与 SSL_ca_file|SSL_ca_path 一起设置为 SSL_VERIFY_PEER 以进行验证。 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.如果您真的不想验证证书并保持连接对中间人攻击开放,请在您的应用程序中将 SSL_verify_mode 显式设置为 SSL_VERIFY_NONE。


at C:/Perl/lib/LWP/Protocol/http.pm line 31.在 C:/Perl/lib/LWP/Protocol/http.pm 第 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?这是一个好兆头吗?

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

$ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = 0;

试试这个

my $UA   = LWP::UserAgent->new( ssl_opts => { verify_hostname => 0, } );

Digging up corpses here but I was in the same position and here is what you need to include in order to fix it ;)在这里挖掘尸体,但我处于相同的位置,这是您需要包含的内容才能修复它;)

$ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = 0;
$ENV{PERL_LWP_SSL_CA_FILE} = "/path/to/your/cert.pem";

Only setting verify_hostnames to 0 is not enough when you play around with self signed certificates.当您使用自签名证书时,仅将 verify_hostnames 设置为 0 是不够的。

None of those solutions worked for me (two and a half years after the last update.. but still the top search result) - I needed an additional package:这些解决方案都不适用于我(上次更新两年半后......但仍然是顶级搜索结果) - 我需要一个额外的包:

cpan install LWP::Protocol::https

without any further alterations to my code.没有对我的代码做任何进一步的修改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM