什么会导致DOMDocument.load从可访问的URL加载XML失败? [英] What would cause DOMDocument.load to fail loading XML from a URL that is accessible?

查看:128
本文介绍了什么会导致DOMDocument.load从可访问的URL加载XML失败?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

$doc = new DOMDocument();
if ($doc->load('http://foo.com/bar.xml')) {
  // good
} else {
  // wtf happened?
}

我可以 wget http://foo.com/bar.xml 从运行PHP代码的位置,所以我知道URL是可访问的。我认为它必须是HTTP错误以外的其他东西。

I can wget http://foo.com/bar.xml from the location where the PHP code is running, so I know the URL is accessible. I'm thinking it must be something other than an HTTP error.

我不知道还有什么可能导致失败。也许解析问题? XML似乎是有效的(并通过W3C的验证测试)。从文档可以看出,无法确定

I'm not sure what else could be causing the failure. Maybe a parsing issue? The XML appears to be valid (and passes W3C's validation test). As far as I can tell from the documentation, there's no way to determine why the load failure occurred.

这是XML:

 <response> 
  <version>8</version> 
  <minversion>1</minversion> 
  <url>api.asp?</url> 
 </response>


推荐答案

我终于把它缩小到一个 PHP配置设置,名为 allow_url_fopen ,它在运行脚本的服务器上设置为关闭

I finally narrowed it down to a PHP configuration setting called allow_url_fopen, which was set to Off on the server running the script.

I修改 php.ini 文件以启用此设置:

I modified the php.ini file to enable this setting:

allow_url_fopen = On

现在 DOMDocument.load 可以加载来自远程URL的XML。

And now DOMDocument.load can load XML from a remote URL.

警告:显然有一些安全问题,永久保持此设置。

WARNING: apparently there are some security issues with keeping this setting on permanently.

这篇关于什么会导致DOMDocument.load从可访问的URL加载XML失败?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆