用perl连https server总是有错误

用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

不懂。帮你顶一下。关注一.
不懂。帮你顶一下。关注一下。

405 Method Not Allowed这个错误我也遇到过。是因为使用modperl的内部重定向,modperl的内部冲定向会把你的数据一起发给目标代码,包含POST数据。所以当你POST给html页的时候就出405了。不过这个和你这个没关系吧?
你请求的是一个 xml 文件,为什么用 post 提交?

如果装了 https 的支持,LWP 使用 https 的时候不用加上certificate 或调用 Crypt::SSLeay ,就和在 http 里使用一样。

另外, 看一下我翻译的 LWP 与 WEB 的基本使用 http://www.perlchina.org/archive/archive.php?action=archive&page=15

你的这个程序可以精简很多,而且里面也有 https 使用的一点介绍。perlchina.org 首页上还有更多的翻译文章。
1.我请求的不是xml文件,是一个perl module
2.我配置的https server要求客户端提供某ca签名的证书,所以程序中要带客户端证书和私钥。
如果不要求客户端提供证书,我的程序也可以通过
3.我看过oreilly的perl and lwp