我想将来自第三方服务器的远程动态 XML 文件加载到我的 GAE-PHP 应用程序中:
$itemId = 5;
$uri = "http://www.myserver.com/getInfoItem.php?itemId={$itemId}&format=xml";
我尝试使用 simplexml_load_file 函数加载 XML 信息:
if ($xmlItem = simplexml_load_file($uri)) {
// Code dealing with the XML info
}
但这总是导致这个错误:
PHP Warning: simplexml_load_file(): I/O warning : failed to load external entity "..."
因此,我更改了代码并尝试将 XML 作为通用文本文件加载。这样,它按预期工作:
if ($fileContents = file_get_contents($uri)) {
$xmlItem = simplexml_load_string($fileContents);
// Code dealing with the XML info
}
我在想这两个函数使用相同的http wrapper获取远程内容,但这似乎不起作用。我也看过 GAE URL Fetch文档。
我的问题是:为什么第一种方法不起作用?我错过了什么吗?