我正在尝试从namecheap解析以下已清理的api响应:
<ApiResponse xmlns="http://api.namecheap.com/xml.response" Status="OK">
<Errors/>
<Warnings/>
<RequestedCommand>namecheap.domains.getlist</RequestedCommand>
<CommandResponse Type="namecheap.domains.getList">
<DomainGetListResult>
<Domain ID="########" Name="website1.com" User="user1" Created="08/18/2014" Expires="08/18/2016" IsExpired="false" IsLocked="false" AutoRenew="false" WhoisGuard="NOTPRESENT"/>
<Domain ID="########" Name="website2.com" User="user1" Created="08/25/2015" Expires="08/24/2016" IsExpired="false" IsLocked="false" AutoRenew="false" WhoisGuard="NOTPRESENT"/>
</DomainGetListResult>
<Paging>
<TotalItems>2</TotalItems>
<CurrentPage>1</CurrentPage>
<PageSize>20</PageSize>
</Paging>
</CommandResponse>
<Server>Servername</Server>
<GMTTimeDifference>--4:00</GMTTimeDifference>
<ExecutionTime>0.034</ExecutionTime>
</ApiResponse>
这是我到目前为止最接近的,但它仍然没有。
$url="https://api.namecheap.com/xml.response?ApiUser=user1&ApiKey=StackExchangeRocks&UserName=user1&Command=namecheap.domains.getList&ClientIp=127.0.0.1";
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url); // get the url contents
$data = curl_exec($ch); // execute curl request
curl_close($ch);
$xml = simplexml_load_string($data);
foreach ($xml->CommandResponse->DomainGetListResult->Domain as $domain) {
echo $domain->Name, PHP_EOL;
}
我所做的几乎所有操作都会遇到错误,指出找不到对象或根本没有响应。
我需要做的就是能够提取域名以便能够将它们存储在数据库中。有什么想法吗?