我们已经获得以下xml
并需要转换为Perl。
POST /carrierintegrationapi.asmx HTTP/1.1
Host: carrierintegrationapi.3tlogistics.net
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "https://carrierintegrationapi.3tlogistics.net/Login"
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<CiSoapHeader xmlns="https://carrierintegrationapi.3tlogistics.net/">
<Username>cccict</Username>
<Password>xxxxxx</Password>
<AuthenticationToken>string</AuthenticationToken>
</CiSoapHeader>
</soap:Header>
<soap:Body>
<Login xmlns="https://carrierintegrationapi.3tlogistics.net/" />
</soap:Body>
</soap:Envelope>';
我们的尝试:
my $service = SOAP::Lite
-> service ('https://carrierintegrationapi.3tlogistics.net/carrierintegrationapi.asmx');
my $AuthHeader = SOAP::Header->new(
name =>'AuthenticationHeader',
attr => { xmlns => "https://carrierintegrationapi.3tlogistics.net/" },
value => {Username => 'cccict', Password => 'xxxxxx' },
);
my $result = $service->GetIt($AuthHeader);
我们在parser.pm
中收到了不匹配的标记?
答案 0 :(得分:0)
由于到目前为止还没有答案,我将向您展示另一种选择。 您可以将请求作为原始帖子提交。可以在标头中声明SOAPAction。使用SOAP :: Lite编译正确的SOAP是耗时的,并且嵌套元素难以阅读。该示例还支持开箱即用的非阻塞调用样式,并进行了少量修改。
use Mojo::UserAgent;
use strict;
use warnings;
# User-Agent
my $ua = Mojo::UserAgent->new;
my $username = 'Username';
my $password = 'Password';
my $authtoken = 'Token';
my $message = <<"SOAP_REQUEST";
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<CiSoapHeader xmlns="https://carrierintegrationapi.3tlogistics.net/">
<Username>$username</Username>
<Password>$password</Password>
<AuthenticationToken>$authtoken</AuthenticationToken>
</CiSoapHeader>
</soap:Header>
<soap:Body>
<Login xmlns="https://carrierintegrationapi.3tlogistics.net/" />
</soap:Body>
</soap:Envelope>
SOAP_REQUEST
my $tx = $ua->post('https://carrierintegrationapi.3tlogistics.net/carrierintegrationapi.asm' => { 'Hello' => "I'm a Header" } => $message);
print $tx->res->body;