我正在尝试用perl为JAX-WS web服务制作SOAP客户端,并进行身份验证。我可以在没有身份验证的情况下与服务进行通信。但是,当我尝试与实际的web Serivce(具有身份验证功能)通信时,我会遇到授权错误或soap-xml非匹配错误。
试试这个代码
my $user="testUser";
my $password="testPassword";
my $service_url='https://api.example.com/services/soap.wsdl';
my $client = SOAP::Lite->service($service_url);
$client->on_fault(
sub { # SOAP fault handler
my $soap = shift;
my $res = shift;
# Map faults to exceptions
if(ref($res) eq '') {
die($res);
} else {
die($res->faultstring);
}
return new SOAP::SOM;
}
);
my @headers = (
SOAP::Header->name('username')->value($user),
SOAP::Header->name('password')->value($password),
);
# make the call
my $result = $client->getVersion(@headers);
print $result . "nn";