how to parse the output of SOAP response which is

2019-08-30 01:46发布

#perl!
use warnings;
use strict;
use XML::Compile::SOAP;
use XML::Compile::SOAP11;
use XML::Compile::WSDL11;
use XML::Compile::Transport::SOAPHTTP;
use Data::Dumper;
##my other variables pointing to wsdl and xsd files.
my $url="http://myhost.com:9080/imws/services/ImpactManager/";
my %inargs_connect = (
    "userName"  => "xxxx",
    "password" => "xxxxxxxxxx",
    "imname"  => "yyyyyyyyyyy",
    "bufferType"  => "abcd"
);

my $wsdl = XML::Compile::WSDL11->new;
$wsdl->addWSDL($wsdl_file);
$wsdl->compileCalls(address =>$url);
my ($answer, $trace) = $wsdl->call( 'Connect', %inargs_connect);
print ($answer);

the above code is printing : HASH(0x47f8b28)

in the last print statement if i use dumper, i get the below response. print Dumper($answer);

$VAR1 = {
          'outargs' => {
                         'connectionId' => '1557666855346'
                       }
        };

how to parse the required values like, i need to be able to easily access 'connectionId' and '1557666855346' ?

Any ideas are welcome. Thanks in advance. Thanks, Kaushik KM.

3条回答
Emotional °昔
2楼-- · 2019-08-30 02:24

loop through all the keys in answear = { outargs => { key1, key2 }}

# This should remove the error of "Experimental keys on scalar is now forbidden" by wrapping the hashRef in %{}
for ( keys %{$answear->{outargs}}) {
    # $_ here will be the key and if you want to access the value use $answear->{outargs}->{$_}
    print "key: $_, value: $answear->{outargs}->{$_}\n";
}

output:

key: connectionId, value: 1557666855346

I hope this will help you!

查看更多
放我归山
3楼-- · 2019-08-30 02:25
my %fhash = %{$answer};
my $key = "";
foreach $key (keys %fhash)
{
print "keys are\n \"$key\" its value is (${$answer}{$key}) \n";

    foreach my $key2 (keys %${$answer}{$key})
    {
    print "keys of(${$answer}{$key})\n \"$key2\"\n";
    }
}

is not working and is throwing error as follows: Experimental keys on scalar is now forbidden at CreateEvent.pl line 64. Type of arg 1 to keys must be hash or array (not key/value hash slice) at Create Event.pl line 64, near "}

can someone correct this please.

查看更多
Evening l夕情丶
4楼-- · 2019-08-30 02:26

$answer appears to be a hash reference, so you'd access the data using normal dereferencing techniques:

my $conn_id = $answer->{outargs}{connectionId};
print "$conn_id\n";

Output:

1557666855346
查看更多
登录 后发表回答