大家!
我在使用 perl 中的 SOAP:Lite 库解析 SOAP 请求的响应时遇到了麻烦。
这是我使用 SOAP 发送的 XML 请求:
SOAP::Transport::HTTP::Client::send_receive: HTTP::Request=HASH(0x9c62028)
SOAP::Transport::HTTP::Client::send_receive: POST https://109.235.185.235:8443/tvrauto
HTTP/1.1
Accept: text/xml
Accept: multipart/*
Accept: application/soap
Content-Length: 571
Content-Type: text/xml; charset=utf-8
SOAPAction: "soapenv#PutCoord"
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ws="soapenv" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<ws:PutCoord>
<ObjectID>79032058458</ObjectID>
<Coord time="2010-01-29T01:28:01Z" lon="37.754689" lat="55.6586458" speed="20.1" dir="301" valid="1"/>
</ws:PutCoord>
</soapenv:Body>
</soapenv:Envelope>
这是来自远程服务器的 XML 答案:
<?xml version="1.0" encoding="windows-1251"?>
<soapenv:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope">
<soapenv:Header/>
<soapenv:Body>
<ws:PutCoordResponse>
<ObjectID>79032058458</ObjectID>
</ws:PutCoordResponse>
</soapenv:Body>
</soapenv:Envelope>
以下是来自 SOAP::Lite 的错误列表:
Unresolved prefix 'soapenv' for element 'Envelope'
Wrong SOAP version specified. Supported versions:
1.1 (http://schemas.xmlsoap.org/soap/envelope/)
1.2 (http://www.w3.org/2003/05/soap-envelope)
Unresolved prefix 'soapenv' for element 'Header'
Unresolved prefix 'soapenv' for element 'Body'
Unresolved prefix 'ws' for element 'PutCoordResponse'
这是 Perl 代码:
#!/usr/bin/perl
use SOAP::Lite +autodispatch;
use SOAP::Lite +trace;
use SOAP::Transport::HTTP;
sub SOAP::Transport::HTTP::Client::get_basic_credentials {
return 'yyyyyy' => 'xxxxxxxxxx';
}
$soap = SOAP::Lite
-> uri('soapenv')
-> proxy('https://109.235.185.235:8443/tvrauto');
$soap->default_ns('https://109.235.185.235:8443','soapenv');
$soap->ns('soapenv', 'ws');
$soap->envprefix('soapenv');
$soap->uri('soapenv');
$soap->soapversion('1.2');
$xml=<<XML;
<ObjectID>79032058458</ObjectID>
<Coord time="2010-01-29T01:28:01Z" lon="37.754689" lat="55.6586458" speed="20.1" dir="301" valid="1"/>
XML
$params=SOAP::Data->type('xml' => $xml);
print $soap->PutCoord($params)->result;
print "\n";
问题是 - 如何避免“未解决的前缀”错误。我尝试以不同的组合使用 uris 和命名空间,但没有得到任何结果。
和相关问题 - SOAP 版本有什么问题?正如我所看到的 - 服务器没有返回给我们任何版本信息。
先感谢您。很抱歉提出愚蠢的问题 - 我根本不熟悉 SOAP :( 期待您的回复。