Perl:我应该向 delcampe API 提供什么样的数据?

发布于 2025-01-06 13:17:42 字数 1944 浏览 1 评论 0原文

我基于 Delcampe API 编写肥皂客户端。简单的方法工作正常,但需要复杂数据的函数会给我一条错误消息,例如“您必须发送项目的数据!”。基于 PHP 示例此处我认为,该数据应该是散列或散列引用,但两者都给我前面提到的错误。

我使用的示例脚本:

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

my $API_key = 'xyz';
my $service = SOAP::Lite->service('http://api.delcampe.net/soap.php?wsdl');
my $return = $service->authenticateUser($API_key);

if ($return->{status}) {
    my $key = $return->{data};
    my %data = (description => 'updated description');
    my $response = $service->updateItem($key, 123456, \%data);

    if ($response->{status}) {
        say Dumper $response->{data};
    } else {
        say $response->{errorMsg};
    } 
} else {
    say "no: " . $return->{status};
}

那么,我应该使用哪种数据结构来代替 %data 或者如何调试根据请求生成的 SOAP 信封? (基于示例的 PHP 代码工作正常)

ADDITION

use SOAP::Lite qw(trace); igot SOAP 信封:

<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:soap-enc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://api.delcampe.net/soap.php">
    <soap:Body>
        <tns:updateItem>
            <token xsi:type="xsd:string">secret_one</token>
            <id_item xsi:type="xsd:int">123456</id_item>
            <arrData xsi:nil="true" xsi:type="soap-enc:Array" />
        </tns:updateItem>
    </soap:Body>
</soap:Envelope>

如上所示,没有任何数据位发送。我也尝试将数据作为字符串、数组和数组引用。也许这是 SOAP::Lite 的错误?

I write soap-client based on Delcampe API. Simple methods work fine, but functions with need on complex data give me an error message like "You must send item's data!". Based on PHP example here i thought, that data should be either hash or hashref, but both give me error mentioned before.

Sample script i use:

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

my $API_key = 'xyz';
my $service = SOAP::Lite->service('http://api.delcampe.net/soap.php?wsdl');
my $return = $service->authenticateUser($API_key);

if ($return->{status}) {
    my $key = $return->{data};
    my %data = (description => 'updated description');
    my $response = $service->updateItem($key, 123456, \%data);

    if ($response->{status}) {
        say Dumper $response->{data};
    } else {
        say $response->{errorMsg};
    } 
} else {
    say "no: " . $return->{status};
}

So, what kind of data structure should i use instead of %data or how could i debug the SOAP-envelope, which is produced as request? (PHP code based on example works fine)

ADDITION

with use SOAP::Lite qw(trace); igot SOAP envelope too:

<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:soap-enc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://api.delcampe.net/soap.php">
    <soap:Body>
        <tns:updateItem>
            <token xsi:type="xsd:string">secret_one</token>
            <id_item xsi:type="xsd:int">123456</id_item>
            <arrData xsi:nil="true" xsi:type="soap-enc:Array" />
        </tns:updateItem>
    </soap:Body>
</soap:Envelope>

As seen above, there is no bit of data sent. I tried data also as string, array and arrayref. Maybe it is bug of SOAP::Lite?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小红帽 2025-01-13 13:17:42

也许您会尝试替换

我的 %data = (description => 'updated description');

我的 $data = SOAP::Data->name(description => '更新的描述');

我们在使用 SOAP API 时遇到了类似的问题,并且通过类似的方法将复杂的数据包装到 SOAP::Data 中来解决。所以我希望这会有所帮助。 )

更新:

之前的建议没有帮助:看起来确实是 SOAP::Lite 错误,它忽略了 WSDL 文件中的“soap-enc:Array”定义。

不过,终于找到了解决方法。这并不漂亮,但作为最后的手段,它可能会起作用。

首先,我从 Delcampe 站点手动下载了 WSDL 文件,将其保存到本地目录中,并将其称为……

my $service = SOAP::Lite->service('file://...delcampe.wsdl')

,因为需要绝对路径。

然后我注释掉了 WSDL updateItem 定义中的“arrData 行”。

最后,我做了这个:

my $little_monster = SOAP::Data->name(arrData => 
  \SOAP::Data->value((
    SOAP::Data->name(item => 
        \SOAP::Data->value(
          SOAP::Data->name(key => 'personal_reference'),
          SOAP::Data->name(value => 'Some Personal Reference')->type('string'),
        )
     ),
     SOAP::Data->name(item => 
        \SOAP::Data->value(
          SOAP::Data->name(key => 'title'),
          SOAP::Data->name(value => 'Some Amazing Title')->type('string'),
        )
     ),
     # ... 
  ))
)->type('ns1:Map');

……而且,我承认,通过……成功地将它释放到荒野中

$service->updateItem($key, 123456, $little_monster);

……这至少产生了或多或少讨人喜欢的信封。

我真诚地希望这至少可以让一些可怜的灵魂免于像我所做的那样用头撞墙。 )

May be you'd try to replace

my %data = (description => 'updated description');

with

my $data = SOAP::Data->name(description => 'updated description');

We have similar issues when working on our SOAP API, and it was solved by something like that, wrapping complex data into SOAP::Data. So I hope this'll help. )

UPDATE:

The previous advice didn't help: looks like it's indeed the SOAP::Lite bug, which ignores the 'soap-enc:Array' definition in WSDL file whatsoever.

Have finally found a workaround, though. It's not pretty, but as a final resort it may work.

First, I've manually downloaded the WSDL file from Delcampe site, saved it into local directory, and referred to it as ...

my $service = SOAP::Lite->service('file://...delcampe.wsdl')

... as absolute path is required.

Then I've commented out the 'arrData line' within WSDL updateItem definition.

And, finally, I've made this:

my $little_monster = SOAP::Data->name(arrData => 
  \SOAP::Data->value((
    SOAP::Data->name(item => 
        \SOAP::Data->value(
          SOAP::Data->name(key => 'personal_reference'),
          SOAP::Data->name(value => 'Some Personal Reference')->type('string'),
        )
     ),
     SOAP::Data->name(item => 
        \SOAP::Data->value(
          SOAP::Data->name(key => 'title'),
          SOAP::Data->name(value => 'Some Amazing Title')->type('string'),
        )
     ),
     # ... 
  ))
)->type('ns1:Map');

... and, I confess, successfully released it into the wilderness by ...

$service->updateItem($key, 123456, $little_monster);

... which, at least, generated more-o-less likable Envelope.

I sincerely hope that'll save at least some poor soul from banging head against the wall as much as I did working on all that. )

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文