0

我们得到了以下内容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

4

1 回答 1

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;
于 2016-06-29T05:35:53.570 回答