使用 SOAP::WSDL 将 SOAP 功能从 PHP 迁移到 Perl [英] Migrating SOAP functionality from PHP to Perl using SOAP::WSDL
问题描述
我正在努力让 SOAP 在 perl 中工作.
I'm struggling to get SOAP working in perl.
在 PHP 中它运行良好,没有任何问题.现在我正在尝试用 Perl 做同样的事情.
In PHP it works perfectly, and without any trouble. And now I'm trying to do the same thing in Perl.
函数式 PHP 是:
$client = new SoapClient("http://thirdpartyurl.com/api.aspx?WSDL");
$info = $client->GetSomeInfo(array('username' => 'myusername', 'password' => 'mypassword'));
这很好用,但我不能让它在 perl 中工作.我尝试了 SOAP::Lite,但没有取得任何进展.我现在正在尝试 SOAP::WSDL:
Which works great, but I just can't get it working in perl. I tried SOAP::Lite, but didn't make any progress. And I'm now trying SOAP::WSDL:
use SOAP::WSDL;
my $wsdl = SOAP::WSDL->new(wsdl => 'http://thirdpartyurl.com/api.aspx?WSDL');
my $info = $wsdl->call('GetSomeInfo', 'username', 'myusername', 'password', 'mypassword');
这是行不通的.我查看了原始请求,perl 版本甚至没有发送用户/传递参数.我做错了什么?
Which just doesn't work. I looked at the raw requests, and the perl version isn't even sending the user/pass parameters through. What am I doing wrong?
推荐答案
为了它的价值,我实现了身份验证,并设法使用以下方法获取参数:
For what it's worth, I achieved authentication, and managed to get parameters sent by using the following:
use SOAP::Lite;
my $service = SOAP::Lite->proxy($service_url)->uri($service_url);
sub SOAP::Transport::HTTP::Client::get_basic_credentials {
return 'myusername' => 'mypassword';
}
my $result = $service->insert(
SOAP::Data->name(
'data' => \SOAP::Data->value(
SOAP::Data->name(
'item' => \SOAP::Data->value(
SOAP::Data->name('key' => 'name'),
SOAP::Data->name('value' => 'new_campaign_x')
)
)
)
)->type('Map')
);
有没有更好的方法来达到同样的结果?我意识到覆盖get_basic_credentials"有点麻烦.
Is there a better way to achieve the same results? I realise overwriting 'get_basic_credentials' is a bit hacky.
这篇关于使用 SOAP::WSDL 将 SOAP 功能从 PHP 迁移到 Perl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!