用perl连https server总是有错误
用perl连https server总是有错误
今用perl写一脚本去连https server,做双方证书验证, 但是验证客户端证书时总是有问题,
用post方法时,报405 Method Not Allowed。用get方法时,看上去没什么问题,但得不到响应。
注:不用https时,都正常。
请诸位帮忙看看,多谢!
#!/usr/bin/perl -w
use warnings;
use strict;
use LWP::UserAgent;
use HTTP::Request;
use HTTP::Response;
use Crypt::SSLeay;
my $xmlMsg =<<XMLMSG;
<?xml version="1.0" encoding="UTF-8"?>
<root>
<wac> </wac>
</root>
XMLMSG
$ENV{HTTPS_VERSION} = '3';
$ENV{HTTPS_DEBUG} = 1;
$ENV{HTTPS_CERT_FILE} = "certificate/client.crt";
$ENV{HTTPS_KEY_FILE} = "certificate/client.key";
$ENV{HTTPS_CA_FILE} = "certificate/ca_cert.crt";
my $browser = LWP::UserAgent->new();
my $request = HTTP::Request->new('GET', 'https://127.0.0.1/xml');
$request->header('Accept' => 'text/xml');
$request->header('Content-type' => 'text/xml; charset=UTF-8');
$request->content($xmlMsg);
print "HTTP Request: \n", $request->as_string, "\n";
my $response = $browser->request($request);
if ($response->is_success())
{
print "HTTP Response: \n", $response->content, "\n";
} else
{
print $response->status_line, "\n";
}
用POST方法,得到的trace:
SSL_connect:before/connect initialization
SSL_connect:SSLv3 write client hello A
SSL_connect:SSLv3 read server hello A
SSL_connect:SSLv3 read server certificate A
SSL_connect:SSLv3 read server key exchange A
SSL_connect:SSLv3 read server done A
SSL_connect:SSLv3 write client key exchange A
SSL_connect:SSLv3 write change cipher spec A
SSL_connect:SSLv3 write finished A
SSL_connect:SSLv3 flush data
SSL_connect:SSLv3 read finished A
405 Method Not Allowed
用GET方法,得到的trace:
SSL_connect:before/connect initialization
SSL_connect:SSLv3 write client hello A
SSL_connect:SSLv3 read server hello A
SSL_connect:SSLv3 read server certificate A
SSL_connect:SSLv3 read server key exchange A
SSL_connect:SSLv3 read server done A
SSL_connect:SSLv3 write client key exchange A
SSL_connect:SSLv3 write change cipher spec A
SSL_connect:SSLv3 write finished A
SSL_connect:SSLv3 flush data
SSL_connect:SSLv3 read finished A
SSL_connect:SSL renegotiate ciphers
SSL_connect:SSLv3 write client hello A
SSL_connect:SSLv3 read server hello A
SSL_connect:SSLv3 read server certificate A
SSL_connect:SSLv3 read server key exchange A
SSL_connect:SSLv3 read server certificate request A
SSL_connect:SSLv3 read server done A
SSL_connect:SSLv3 write client certificate A
SSL_connect:SSLv3 write client key exchange A
SSL_connect:SSLv3 write certificate verify A
SSL_connect:SSLv3 write change cipher spec A
SSL_connect:SSLv3 write finished A
SSL_connect:SSLv3 flush data
SSL_connect:SSLv3 read finished A