这是我的第一个 Perl 脚本。我已经使用 CPAN 安装了 SOAP::Lite,看起来一切顺利。
我正在尝试访问一个简单的 HelloWorld .NET Web 服务。我收到一个错误,该错误似乎与 Perl 或 SOAP::Lite 无法验证 SSL 证书有关。
虽然它看起来返回代码为 500,但我创建了一个能够很好地调用 Web 方法的 Java 客户端,因此我认为问题不在于 Web 服务端。
谁能指出我如何让它发挥作用的正确方向?
Script:
#!/usr/bin/perl
use SOAP::Lite 'trace', 'debug';
$api_ns = "https://www.mydomain.com/edgedev/";
$api_url = "https://www.mydomain.com/edgedev/ws.asmx";
$action = "HelloWorld";
my $soap = SOAP::Lite
-> readable(1)
-> ns($api_ns, 'tns')
-> proxy($api_url)
-> on_action(sub { return "\"$action\""});
print $soap->HelloWorld()->result;
Result
<soap:Envelope
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:tns="https://www.mydomain.com/edgedev/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<tns:HelloWorld xsi:nil="true" />
</soap:Body>
</soap:Envelope>
SOAP::Transport::HTTP::Client::send_receive: 500 Can't connect to www.mydomain.com:443 (certificate verify failed)
Content-Type: text/plain
Client-Date: Tue, 12 Feb 2013 16:40:28 GMT
Client-Warning: Internal response
Can't connect to www.mydomain.com:443 (certificate verify failed)
You can disable hostname check by setting environment variable PERL_LWP_SSL_VERIFY_HOSTNAME=0
LWP::Protocol::https::Socket: SSL connect attempt failed with unknown errorerror:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed at /usr/lib/perl5/vendor_perl/5.10.0/LWP/Protocol/http.pm line 57.
500 Can't connect to www.mydomain.com:443 (certificate verify failed) at ./soaptest.pl line 15
以下是如何使其安全地工作,即不禁用 SSL 主机名检查。
如果您正在与具有 CA 签名证书的公共系统进行通信,则需要将 LWP 指向您的发行版的根证书集合。在基于 Debian 的系统(Ubuntu 等)下,它保存在/etc/ssl/certs/
.
BEGIN {
$ENV{HTTPS_CA_DIR} = '/etc/ssl/certs'
}
如果您使用自签名证书与自己的服务器通信,则可以在客户端上保存该证书的副本,并将脚本指向该特定文件。
BEGIN {
$ENV{HTTPS_CA_FILE} = '/path/to/my/server-certificate.crt'
}
您可以在运行脚本之前在环境中设置这些(例如,从 shell 中导出它们),或者您可以将设置直接应用于 UserAgent 对象。请参阅LWP::UserAgent 文档更多细节;搜索ssl_opts
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)