問題描述
我無法使用 PHP 連接到 Magento SOAP API v2.出現(xiàn)的錯誤是:
I am unable to connect to the Magento SOAP API v2 using PHP. The error that occurs is:
PHP 致命錯誤:未捕獲的 SoapFault 異常:[WSDL] SOAP 錯誤:解析 WSDL:無法從 'http://www.example.com/index.php/api/v2_soap/index/wsdl/1/':無法加載外部實體 "http://www.example.com/index.htmlphp/api/v2_soap/index/wsdl/1/"
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/"
看起來,WSDL 正在加載,但它包含的外部 SOAP 文件沒有加載.
As it seems, the WSDL is being loaded, but the external SOAP file which it includes not.
PHP 連接代碼:
$client = new SoapClient('http://www.example.com/api/v2_soap?wsdl=1');
$session = $client->login('username', 'password');
<小時>
從 v2_soap?wsdl=1 文件中截取:
Snip from v2_soap?wsdl=1 file:
<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 版本為 1.5.1.0
.
推薦答案
此問題是由于服務器無法從本地機器訪問文件造成的.所以可能的原因可能是 DNS 服務器或/etc/hosts,但它實際上是一個 .htaccess 文件阻止了除我們的開發(fā)計算機之外的任何主機.這導致了 403 Forbidden 錯誤,進而導致了 SOAP 錯誤等等.
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..
這篇關于由于“無法加載外部實體",無法連接到 Magento SOAP API v2的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!