2017-04-26 106 views
-1

我正在尝试使用SoftLayer::API::SOAP获取global_ip_id。但是,当我尝试从Softlayer API获取全球IP

$global_ip_id = $client->getGlobalIpRecords()->result->[0]->{id}; 

我得到的错误:

Can't use an undefined value as an ARRAY reference at /usr/bin/reroute_global line 19

+0

欢迎来到[so]!在这个网站,你应该尝试**自己编写代码**。后** [做更多的研究](//meta.stackoverflow.com/questions/261592)**如果你有问题,你可以**发布你已经尝试**与清楚的解释是什么是'工作**并提供[** Minimal,Complete和Verifiable示例**](// stackoverflow.com/help/mcve)。我建议阅读[问]一个好问题和[完美问题](http://codeblog.jonskeet.uk/2010/08/29/writing-the-perfect-question/)。另外,一定要参加[游览]并阅读[this](// meta.stackoverflow.com/questions/347937/)**。 – Badacadabra

回答

0

我不知道什么框架,或者你正在使用的语言,但我prettry肯定,这是错误的使用是一个问题。

SOAP响应,你从电话获得应该是somethign这样

<?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} 

所以我建议你要确保你的语言或框架如何使您可以通过SOAP响应导航,因为目前你所得到的问题是由于您试图访问的方式不对数据。

现在,如果你使用的是SoftLayer的Perl客户,你应该使用这样的事情:

my $client = SoftLayer::API::SOAP->new('SoftLayer_Account', undef, $api_username, $api_key); 
my $output = $client->getGlobalIpRecords(); 
print $output->result->[0]->{'id'}; 

正如你所看到的一切都取决于你所使用

而且万一你是什么lenguage和框架使用Perl的错误可能是由于结果为空,在这种情况下,您需要验证这不是空的,请参阅Error: Can't use an undefined value as an ARRAY reference以获取更多信息。

Regards

+0

嗨尼尔森,谢谢你的答复。我使用Softlayer的Perl,我试过你的例子,但我仍然有相同的错误: –

+0

我跟着这个实现https://serverfault.com/questions/666850/softlayer-haproxy-with-failover –

+0

也许你没有任何全局IP尝试转储结果并查看它是否有数据“print Dumper($ output-> result);” –