jap*_*968 3 php google-app-engine
我想将第三方服务器中的远程动态XML文件加载到我的GAE-PHP应用程序中:
$itemId = 5;
$uri = "http://www.myserver.com/getInfoItem.php?itemId={$itemId}&format=xml";
Run Code Online (Sandbox Code Playgroud)
我尝试使用simplexml_load_file函数加载XML信息:
if ($xmlItem = simplexml_load_file($uri)) {
// Code dealing with the XML info
}
Run Code Online (Sandbox Code Playgroud)
但这总是导致这个错误:
PHP Warning: simplexml_load_file(): I/O warning : failed to load external entity "..."
Run Code Online (Sandbox Code Playgroud)
所以,我已经更改了代码,我尝试将XML加载为通用文本文件.这样,它按预期工作:
if ($fileContents = file_get_contents($uri)) {
$xmlItem = simplexml_load_string($fileContents);
// Code dealing with the XML info
}
Run Code Online (Sandbox Code Playgroud)
我在想这两个函数使用相同的http包装器来获取远程内容,但这似乎不是这样的.我也看过GAE URL Fetch文档.
我的问题是:为什么第一种方法不起作用?我错过了什么吗?
Stu*_*ley 11
我们默认禁用外部实体的自动加载,您必须选择加入.
试试看
libxml_disable_entity_loader(false);
Run Code Online (Sandbox Code Playgroud)
在你打电话之前.这在" 禁用功能"部分中有说明
这需要一个额外的步骤:首先,您必须创建一个包含以下行的php.ini文件:
google_app_engine.enable_functions = "libxml_disable_entity_loader"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1255 次 |
| 最近记录: |