简体   繁体   English

尝试使用Magento的API时出现Soap错误

[英]Soap error when trying to use the API of Magento

I am looking for help with this problem and I hope someone give me that help. 我正在寻找有关此问题的帮助,希望有人能帮助我。 The error is the following: 错误如下:

Fatal error: SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://example.com/index.php/api/?wsdl' : failed to load external entity "http://example.com/index.php/api/?wsdl" in /var/www/presentacion/app/code/local/Pengo/Extension/Model/Something.php on line 28 致命错误:SOAP错误:解析WSDL:无法从“ http://example.com/index.php/api/?wsdl”加载:无法加载外部实体“ http://example.com/index”。第28行的/var/www/presentacion/app/code/local/Pengo/Extension/Model/Something.php中的php / api /?wsdl”

And the code that I'm using to connect to it is something like this: 我用来连接的代码是这样的:

$this->_soap = new SoapClient(http://example.com/index.php/api/?wsdl);

and there is where it says is the error. 并指出错误所在。

I have been serching in Google, PHP forums, here in StackOverflow and Magento itself but I don't find the solution anywhere. 我一直在Google,PHP论坛,StackOverflow和Magento本身中搜索,但是我找不到任何解决方案。

What I had seen is that the WSDL is never get parsed or loaded as the error says and none of its functions. 我所看到的是,WSDL从未像错误所述那样被解析或加载,并且没有任何功能。

I tried connecting like this: 我尝试这样连接:

$options['location'] = http://example.com/index.php/api/?wsdl;
$options['uri'] = 'urn:Magento';
$this->_soap = new SoapClient(null, $options);

like this it doesn't dispatch any error like the others but there aren't functions to use, like in the other case it doesnt' load and parse the WSDL. 这样,它不会像其他错误一样调度任何错误,但是没有要使用的函数,就像在其他情况下,它不会加载和解析WSDL。

I am a bit frustrated because I have been developing this like 1 month and now that I am making some tests it shows this message, I had test it when it was really empty and new and it worked fine. 我有点沮丧,因为我已经像一个月那样开发了它,现在我正在做一些测试来显示此消息,我在它真的是空的并且是新的并且可以正常工作的时候对其进行了测试。

So any help would be appreciated. 因此,任何帮助将不胜感激。

Thank you. 谢谢。

Nine times out of ten this error is Magento is telling you it can't load the WSDL file. 十分之九的错误是Magento告诉您它无法加载WSDL文件。 Magento is telling you this. Magento告诉你这个。 It's not your local client code that's complaining. 抱怨的不是您本地的客户代码。

Magento uses the PHP SoapServer object to create its SOAP API. Magento使用PHP SoapServer对象创建其SOAP API。 The SoapServer object needs to access the WSDL as well. SoapServer对象也需要访问WSDL。 Try running the following from your server's command line 尝试从服务器的命令行运行以下命令

curl http://example.com/index.php/api/?wsdl

If I'm right, the above will timeout/fail. 如果我是对的,则以上将超时/失败。

Because of some quirks in DNS, it's surprisingly common that a server won't be able to access itself via its domain name. 由于DNS中存在一些怪异,服务器无法通过其域名进行访问本身是令人惊讶的普遍现象。 If this is the case, the quickest fix is adding an entry to the server's hosts file. 如果是这种情况,最快的解决方法是将条目添加到服务器的主机文件中。 (Talk to your server admin if none of that made sense) (如果没有任何道理,请与您的服务器管理员联系)

Well after all the things that I test the only one that worked for me, I don't know why but it worked, was doing this in two separate machines. 毕竟,在我测试了唯一对我有用的东西之后,我不知道为什么,但它起作用了,是在两台单独的机器上进行的。 I tried that because I read that somewhere and I just do it and my Magento and Webservice now works perfectly. 我这样做是因为我在某个地方阅读了该书,然后我就完成了,Magento和Webservice现在可以完美运行了。 Whenever I try to do this local it dispatch the same error. 每当我尝试在本地执行此操作时,都会调度相同的错误。

I hope this can help someone in the future and they don't have to knock their head on the wall because of this problem. 我希望这可以在将来对某人有所帮助,而不必因为这个问题而撞墙。

Thank you all for your answers and comments. 谢谢大家的回答和评论。

Alan Storm is right on the Money here! 艾伦·斯托姆(Alan Storm)就在这里赚钱!

Make sure that you check your server Hosts File, and that it includes an entry for both domain and www.domain. 确保检查服务器的主机文件,并且该文件包含域和www.domain的条目。 Espicialy important if you are doing server rewrites. 如果要进行服务器重写,则特别重要。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM