我正在尝试使用SoftLayer::API::SOAP
获得global_ip_id
。但是当我尝试
$global_ip_id = $client->getGlobalIpRecords()->result->[0]->{id};
我得到错误:
不能使用未定义值作为数组参考 /usr/bin/reroute_global线19
我不知道您正在使用哪种框架或语言,但是我曾确保这是错误使用的问题。
您从该电话中获得的肥皂反应应该像这样
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://api.service.softlayer.com/soap/v3.1/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Header>
<ns1:totalItems>
<amount>7</amount>
</ns1:totalItems>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<ns1:getGlobalIpRecordsResponse>
<getGlobalIpRecordsReturn SOAP-ENC:arrayType="ns1:SoftLayer_Network_Subnet_IpAddress_Global[7]" xsi:type="ns1:SoftLayer_Network_Subnet_IpAddress_GlobalArray">
<item xsi:type="ns1:SoftLayer_Network_Subnet_IpAddress_Global">
<description xsi:nil="true"/>
<destinationIpAddressId xsi:nil="true"/>
<id xsi:type="xsd:int">11111</id>
<ipAddressId xsi:type="xsd:int">22222</ipAddressId>
<typeId xsi:type="xsd:int">1</typeId>
</item>
</getGlobalIpRecordsReturn>
</ns1:getGlobalIpRecordsResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
现在,您如何从该响应中获取数据取决于您使用的语言或框架,因为响应是某些语言中的XML,您需要浏览XML的标签,例如。
result->{Body}->{getGlobalIpRecordsResponse}->{getGlobalIpRecordsReturn }->[0]->{id}
因此,我推荐您确保您的语言或框架如何允许您浏览肥皂响应,因为当前您遇到的问题是由于您试图访问数据的错误方式。p>现在,如果您使用的是SoftLayer的Perl客户端,则应使用类似的东西:
my $client = SoftLayer::API::SOAP->new('SoftLayer_Account', undef, $api_username, $api_key);
my $output = $client->getGlobalIpRecords();
print $output->result->[0]->{'id'};
您可以看到,所有这些都取决于您使用的
的框架和框架同样,如果您使用perl,则可能是由于结果为空的,在这种情况下,您需要验证这不是空的,请参见错误:不能将未定义的值用作数组参考以获取更多信息。
问候