问题
I'm struggling to get SOAP working in perl.
In PHP it works perfectly, and without any trouble. And now I'm trying to do the same thing in Perl.
The functional PHP is:
$client = new SoapClient("http://thirdpartyurl.com/api.aspx?WSDL");
$info = $client->GetSomeInfo(array('username' => 'myusername', 'password' => 'mypassword'));
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');
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?
回答1:
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')
);
Is there a better way to achieve the same results? I realise overwriting 'get_basic_credentials' is a bit hacky.
回答2:
I've had pretty good luck with SOAP::Lite in my applications. The username/password combo, is that supposed to be authenticating at the HTTP layer or the SOAP layer? Or just regular soap parameters?
回答3:
When I want to do SOAP, I reach for XML::Compile.
来源:https://stackoverflow.com/questions/1765248/migrating-soap-functionality-from-php-to-perl-using-soapwsdl