Perl中的SOAP客户端

时间:2018-03-08 14:06:27

标签: perl soap wsdl

我试图使用Perl和SOAP :: Lite与https://webapi.allegro.pl.webapisandbox.pl/service.php?wsdl“交谈”。

在PHP中,它就像这样简单:

<?
$client = new SoapClient('https://webapi.allegro.pl.webapisandbox.pl/service.php?wsdl');
$results = $client->doQueryAllSysStatus(array(
    'countryId' => 1,
    'webapiKey' => 'XXXXXX'
));
header('Content-type: text/plain');
var_dump($results);
?>

但是Perl ......不是;)。

我写了这个:

use SOAP::Lite;
my $soap = SOAP::Lite->new(proxy => 'https://webapi.allegro.pl.webapisandbox.pl/service.php?wsdl');
my $som = $soap->call('doQueryAllSysStatus', 1, 'XXXXXX');
# tried also this:
# my $som = $soap->call('doQueryAllSysStatus', 
#     SOAP::Data->name('countryId')->value(1),
#     SOAP::Data->name('webapiKey')->value('XXXXXX')
# );
die $som->faultstring if ($som->fault);
print $som->result, "\n";

$som->result为空。

也试过:

use SOAP::Lite;
my $soap = SOAP::Lite->service('https://webapi.allegro.pl.webapisandbox.pl/service.php?wsdl');
my $r = $soap->doQueryAllSysStatus(1, 'xxxxxx');
print $r, "\n";

......得到Use of uninitialized value $r in print

任何帮助将不胜感激......

更新#1: PHP代码输出:

object(stdClass)#2 (1) {
  ["sysCountryStatus"]=>
  object(stdClass)#3 (1) {
    ["item"]=>
    object(stdClass)#4 (8) {
      ["countryId"]=>
      int(1)
      ["programVersion"]=>
      string(3) "1.0"
      ["catsVersion"]=>
      string(6) "1.4.94"
      ["apiVersion"]=>
      string(3) "1.0"
      ["attribVersion"]=>
      string(3) "1.0"
      ["formSellVersion"]=>
      string(7) "1.11.91"
      ["siteVersion"]=>
      string(3) "1.0"
      ["verKey"]=>
      int(1505223106)
    }
  }
}

2 个答案:

答案 0 :(得分:1)

我找到了一个有效的解决方案,所以对于任何好奇的人来说都是。

我放弃了SOAP::Lite,并在XML::Compile::*的帮助下使用了HTTP::Tiny个模块。

代码:

use Data::Printer;
use HTTP::Tiny;
use XML::Compile::SOAP11;
use XML::Compile::WSDL11;
use XML::Compile::Transport::SOAPHTTP;

my $wsdlXml = HTTP::Tiny->new->get('https://....')->{content};
my $wsdl    = XML::Compile::WSDL11->new($wsdlXml);

my $response = $wsdl->compileCall('doQueryAllSysStatus')->(
    countryId => 1, 
    webapiKey => 'xxxxxx'
);
p $response;

打印出来:

\ {
    parameters   {
        sysCountryStatus   {
            item   [
                [0] {
                    apiVersion        1.0,
                    attribVersion     1.0,
                    catsVersion       "1.4.94",
                    countryId         1,
                    formSellVersion   "1.11.91",
                    programVersion    1.0,
                    siteVersion       1.0,
                    verKey            1505223106
                }
            ]
        }
    }
}

耶! ;)

答案 1 :(得分:0)

我没有网络API密钥,所以我无法完全测试,但这样的事情呢?

#!/usr/bin/perl

use warnings;
use strict;
use SOAP::Lite;

my $soap = SOAP::Lite->new( proxy => 'https://webapi.allegro.pl.webapisandbox.pl/service.php?wsdl');

my $country = 1;
my $api = 'XXXXX';

my $r = $soap->doQueryAllSysStatus($country,$api);

print $r->result, "\n";

---更新---

#!/usr/bin/perl

use warnings;
use strict;
use SOAP::Lite;
use Data::Dumper;

my $soap = SOAP::Lite->new( proxy => 'https://webapi.allegro.pl.webapisandbox.pl/service.php?wsdl');

my $country = 1;
my $api = 'XXXXX';

my @r = $soap->doQueryAllSysStatus($country,$api);

print Dumper(\@r);