调用Namecheap的API有问题吗?

时间:2014-05-26 02:27:04

标签: php xml xml-parsing terminal

我使用this tutorial创建一个简单的PHP文件,该文件使用Namecheap的API来检查域名的可用性。我完全按照教程,所以我的代码是:

<?PHP
$command = 'https://api.sandbox.namecheap.com/xml.response?ApiUser=myusername&ApiKey=myapikeyed&UserName=myusername&Command=namecheap.domains.check&ClientIp='.$_SERVER['REMOTE_ADDR'].'&DomainList=adminpeak.com,kavin12345.com';
$data = file_get_contents($command);
$xml = simplexml_load_string($data);

if( ! $xml)
    {
// Code to do when load failed.
        echo 'unable to load XML file';
    }
    else
    {
// Code to do when load successful.
foreach ($xml->CommandResponse->DomainCheckResult as $result)  {
    echo $result['Domain'].':'. $result['Available'].'<br />';
}
}
?>

但是,当我使用$ php namecheap.php在我的终端中运行它时,收到错误消息:

Warning: Invalid argument supplied for foreach() in /Users/MyName/Documents/NamecheapPHP/namecheap.php on line 14

有什么想法吗?

0 个答案:

没有答案