php 由于“无法加载外部实体”,无法连接到 Magento SOAP API v2
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6454644/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Unable to connect to Magento SOAP API v2 due to "failed to load external entity"
提问by user228395
I am unable to connect to the Magento SOAP API v2 using PHP. The error that occurs is:
我无法使用 PHP 连接到 Magento SOAP API v2。发生的错误是:
PHP Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://www.example.com/index.php/api/v2_soap/index/wsdl/1/' : failed to load external entity "http://www.example.com/index.php/api/v2_soap/index/wsdl/1/"
PHP 致命错误:未捕获的 SoapFault 异常:[WSDL] SOAP 错误:解析 WSDL:无法从“ http://www.example.com/index.php/api/v2_soap/index/wsdl/1/”加载:无法加载外部实体“ http://www.example.com/index.php/api/v2_soap/index/wsdl/1/”
As it seems, the WSDL is being loaded, but the external SOAP file which it includes not.
看起来,WSDL 正在加载,但它包含的外部 SOAP 文件没有加载。
PHP connection code:
PHP连接代码:
$client = new SoapClient('http://www.example.com/api/v2_soap?wsdl=1');
$session = $client->login('username', 'password');
Snip from v2_soap?wsdl=1 file:
从 v2_soap?wsdl=1 文件中截取:
<service name="MagentoService">
<port name="Mage_Api_Model_Server_V2_HandlerPort" binding="typens:Mage_Api_Model_Server_V2_HandlerBinding">
<soap:address location="http://www.example.com/index.php/api/v2_soap/index/"/>
</port>
</service>
Magento version is 1.5.1.0
.
Magento 版本是1.5.1.0
.
采纳答案by user228395
This problem is caused by the server not being able to access the file from the local machine. So the possible cause could've been the DNS server or /etc/hosts, but it was actually a .htaccess file blocking any hosts except from our development computers. This resulted in a 403 Forbidden error, which resulted in the SOAP error and so on..
此问题是由服务器无法从本地计算机访问文件引起的。所以可能的原因可能是 DNS 服务器或 /etc/hosts,但它实际上是一个 .htaccess 文件阻止了除了我们的开发计算机之外的任何主机。这导致了 403 Forbidden 错误,从而导致了 SOAP 错误等等。
回答by Francois Deschenes
I've experience a similar problem recently on a public-facing development server. The problem was the I was using a .htaccess
file to prevent unauthorized use of the site and I forgot to add the server's own IP addresses to the list. Once I added it, it solved the problem.
我最近在面向公众的开发服务器上遇到了类似的问题。问题是我正在使用一个.htaccess
文件来防止未经授权使用该站点,而我忘记将服务器自己的 IP 地址添加到列表中。一旦我添加它,它就解决了问题。
Make sure that you don't have any rules forbidding access to your content.
确保您没有任何禁止访问您的内容的规则。
回答by Kelly L.
Make sure that php.ini enables SSL. add this to your file: extension=php_openssl.dll
确保 php.ini 启用 SSL。将此添加到您的文件中:extension=php_openssl.dll
I had this problem and that was what fixed it.
我遇到了这个问题,这就是解决它的原因。
回答by Doug McLean
tl;dr:Check the API username and API key.
tl;dr:检查 API 用户名和 API 密钥。
Unfortunately, SOAP is giving you a generic error message which could mean a number of things.
不幸的是,SOAP 向您提供了一个通用的错误消息,这可能意味着很多事情。
One possible candidate is a routing problem, i.e. the server tries to send itself a request but it fails, perhaps because it's using its own public IP address to do so and this doesn't work, because of reasons.
一个可能的候选者是路由问题,即服务器尝试向自己发送请求,但失败了,可能是因为它使用自己的公共 IP 地址这样做,但由于某些原因,这不起作用。
To see if this is the case on your server, log into it (e.g. with SSH) and try pinging the hostname. If the ping works, routing is almost certainly not the problem. If the ping fails, try adding the hostname into your hosts file (typically /etc/hosts) with the IP address 127.0.0.1 (or ::1 if you're into IPv6).
要查看您的服务器是否是这种情况,请登录(例如使用 SSH)并尝试 ping 主机名。如果 ping 工作正常,路由几乎肯定不是问题。如果 ping 失败,请尝试将主机名添加到您的主机文件(通常是 /etc/hosts)中,IP 地址为 127.0.0.1(如果您使用的是 IPv6,则为 ::1)。
Butanother possible reason, and one I experienced myself recently, is simply that you've not provided the correct API username and API key. SOAP - at least, the way Magento implements it - doesn't seem to have an "access denied" or "login failed" response. Because of this, it's hopeless testing API functions in a browser.http://www.example.com/api/v2_soap?wsdl=1works in a browser as the WSDL isn't password-protected. But the endpoint itself is, so http://www.example.com/index.php/api/v2_soap/index/* will fail.
但另一个可能的原因,也是我最近亲身经历的一个原因,就是您没有提供正确的 API 用户名和 API 密钥。SOAP - 至少,Magento 实现它的方式 - 似乎没有“访问被拒绝”或“登录失败”响应。因此,在浏览器中测试 API 功能是无望的。http://www.example.com/api/v2_soap?wsdl=1可在浏览器中使用,因为 WSDL 不受密码保护。但是端点本身是,所以http://www.example.com/index.php/api/v2_soap/index/*会失败。
One other possiblity, did you change your store's domain name recently and not flush the "webservices configuration files" caches?
另一种可能性,您最近是否更改了商店的域名并且没有刷新“webservices 配置文件”缓存?
回答by Jongosi
This error could also be related to the SSL ciphers that your server is set to use. The current recommended suite of ciphers (note that these will need updating in time) is ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+3DES:DH+3DES:RSA+AESGCM:RSA+AES:RSA+3DES:!aNULL:!MD5:!DSS
.
此错误也可能与您的服务器设置为使用的 SSL 密码有关。当前推荐的密码套件(请注意,这些将需要及时更新)是ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+3DES:DH+3DES:RSA+AESGCM:RSA+AES:RSA+3DES:!aNULL:!MD5:!DSS
.
Obviously you should follow the recommended procedure to update your relevant OS and it's SSL ciphers.
显然,您应该按照推荐的程序更新您的相关操作系统及其 SSL 密码。
If your server is running Plesk Control Panel, versions 11 onwards, there is a particular fix:
如果您的服务器运行的是 Plesk 控制面板,版本 11 或更高版本,则有一个特定的修复程序:
Upgrade the 'openssl' package to version 1.0 and higher.
Enable nginx:
/usr/local/psa/admin/bin/nginxmng --enable
Create a custom domain template for nginx:
mkdir -p /usr/local/psa/admin/conf/templates/custom/domain/
cp /usr/local/psa/admin/conf/templates/default/domain/nginxDomainVirtualHost.php /usr/local/psa/admin/conf/templates/custom/domain
Edit the file you just copied:
vi /usr/local/psa/admin/conf/templates/custom/domain/nginxDomainVirtualHost.php
Look for the line
<?php if ($OPT['ssl']): ?>
and insert the following immediately after:ssl_protocols TLSv1.1 TLSv1.2; ssl_ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+3DES:DH+3DES:RSA+AESGCM:RSA+AES:RSA+3DES:!aNULL:!MD5:!DSS;
Save the file.
Reconfigure the vhosts.
/usr/local/psa/admin/bin/httpdmng --reconfigure-all
将“openssl”包升级到 1.0 及更高版本。
启用 Nginx:
/usr/local/psa/admin/bin/nginxmng --enable
为 nginx 创建自定义域模板:
mkdir -p /usr/local/psa/admin/conf/templates/custom/domain/
cp /usr/local/psa/admin/conf/templates/default/domain/nginxDomainVirtualHost.php /usr/local/psa/admin/conf/templates/custom/domain
编辑刚刚复制的文件:
vi /usr/local/psa/admin/conf/templates/custom/domain/nginxDomainVirtualHost.php
查找该行
<?php if ($OPT['ssl']): ?>
并在其后立即插入以下内容:ssl_protocols TLSv1.1 TLSv1.2; ssl_ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+3DES:DH+3DES:RSA+AESGCM:RSA+AES:RSA+3DES:!aNULL:!MD5:!DSS;
保存文件。
重新配置虚拟主机。
/usr/local/psa/admin/bin/httpdmng --reconfigure-all
Credit: This fix is documented by Odin directly: http://kb.odin.com/en/120083
信用:此修复程序由 Odin 直接记录:http: //kb.odin.com/en/120083
回答by Devendra Gupta
Go To Admin Dash board > system > configuration > web > Search engine Optimization > Use web Server rewrite "Set it to No"
转到管理仪表板 > 系统 > 配置 > Web > 搜索引擎优化 > 使用 Web 服务器重写“将其设置为否”
For me it was the Fix.
对我来说这是修复。
回答by Gregory Rios
I wanted to contribute the following, depending on the server and the Magento configuration, this simple solution can work. is to add the index.php to the URL
我想贡献以下内容,根据服务器和 Magento 配置,这个简单的解决方案可以工作。是将 index.php 添加到 URL
$client = new SoapClient('https://www.TU-domain.com/index.php/api/v2_soap/?wsdl');
$client = new SoapClient(' https://www.TU-domain.com/index.php/api/v2_soap/?wsdl');
回答by Jeff Thomas
Are you on a shared hosting account? It is possible that your provider is blocking access to the port.
您使用的是共享主机帐户吗?您的提供商可能阻止访问该端口。