我正在尝试使用 SOAP::Lite 模块进行简单的 API 调用(至少这是我开始时的想法)。我在这里使用公开可用的 SOAP API 之一来添加两个数字。我收到以下错误:
服务器无法识别 HTTP Header SOAPAction: http://tempuri.org/#Add的值。
我在 SOAP::Lite 中启用了调试,看来我的请求格式不正确。我怀疑 intA 和 intB 中指定的类型 (xsi:type="xsd:int") 引起了问题。
调试请求:
<?xml version="1.0" encoding="UTF-8"?> <soap:Envelope
soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Body>
<Add xmlns="http://tempuri.org/">
<intA xsi:type="xsd:int">5</intA>
<intB xsi:type="xsd:int">10</intB>
</Add>
</soap:Body> </soap:Envelope>
这是我的 Perl 代码:
#!/usr/bin/env perl
use strict;
use warnings;
use SOAP::Lite;
#use SOAP::Lite +trace => 'all';
SOAP::Lite->import(trace => 'debug');
#my $uri = 'http://tempuri.org/';
my $proxy = 'http://www.dneonline.com/calculator.asmx';
my $ns = 'http://tempuri.org/';
my $client = SOAP::Lite
->readable(1)
->uri($ns)
->proxy($proxy);
my $param1 = SOAP::Data->name("intA" => $x);
my $param2 = SOAP::Data->name("intB" => $y);
my $response = $client->Add($param1,$param2);
print "Result is $response \n";
注意:我尝试在 SOAPUI 工具中加载 WSDL,并且 API 在那里工作正常。
更新
正如@simbabque 建议的那样,我尝试使用 LWP::ConsoleLogger 进行调试
标题如下所示:
.---------------------------------+-----------------------------------------.
| Request (before sending) Header | Value |
+---------------------------------+-----------------------------------------+
| Accept | text/xml, multipart/*, application/soap |
| Content-Length | 549 |
| Content-Type | text/xml; charset=utf-8 |
| SOAPAction | "http://tempuri.org/#Add" |
| User-Agent | SOAP::Lite/Perl/1.27 |
'---------------------------------+-----------------------------------------'
我不知道#是从哪里来的。也许我会尝试 SOAP::Simple 看看它是否有帮助。
干杯