1

我正在尝试在 perl 中为带有身份验证的 JAX-WS Web 服务制作 SOAP 客户端。我无需身份验证即可与服务进行通信。但是,当我尝试与实际的网络服务(具有身份验证)进行通信时,我收到授权错误或肥皂 xml 未格式化错误。

4

1 回答 1

2

试试这个代码

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 . "\n\n";
于 2013-02-06T11:57:33.780 回答