【发布时间】:2018-10-09 08:30:36
【问题描述】:
我正在尝试使用 SOAP::Lite 模块进行简单的 API 调用(至少我一开始是这么想的)。我正在使用公开可用的 SOAP API here 之一来添加两个数字。我收到以下错误:
服务器无法识别 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 看看是否有帮助。
干杯
【问题讨论】:
-
#看起来很奇怪。你知道这是从哪里来的吗? -
SOAP::Lite 在后台使用 LWP。 LWP::ConsoleLogger 可能是一个很好的调试辅助工具。
-
嗨@simbabque,感谢您的回复。我已经从 LWP::ConsoleLogger 添加了标题信息。我在跟踪中随处看到带有 uri 的 # 符号。不确定,它来自哪里。
-
如果您可以选择想要使用的内容,请查看 XML::Compile::SOAP。它有一点学习曲线,但实际上非常好。
-
谢谢@simbabque,我也试试看。