Soap::Lite Perl Basic Query

情到浓时终转凉″ 提交于 2020-01-07 07:43:11

问题


We have been given the below xml and need to translate into 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>';

Our attempt:

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);

We get mismatched tag in parser.pm?


回答1:


Since there is no answer so far, I'm goingo to show you an alternative. You can submit the request as raw post. SOAPAction might be declared in the header. Compiling the correct SOAP with SOAP::Lite is time intensive and nested elements are hard to read. The example does also support non-blocking calling style out of the box with a small modification.

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;


来源:https://stackoverflow.com/questions/38082603/soaplite-perl-basic-query

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!