在使用SOAP调用ASMX文件做接口开发的时候,有些接口偶尔会报错,但是一直找不到原因.
错误提示如下:
Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://www.test.com.cn/test/test.asmx?wsdl' : failed to load external entity
重点错误提示在这句:failed to load external entity
各种搜索,各种坑,都无效.
最后参考大神博客发现,按下面的方案可以解决
If libxml_disable_entity_loader() has been called already, add before each SoapClient instantiation:
libxml_disable_entity_loader(false);
Above any calls to instantiate SoapClient.
也就是在所有你实例化soap类的前面,申明个东西,例如:
function soap_post_asus($params,$func)
{
libxml_disable_entity_loader(false); //加上这句
$client = new SoapClient('http://www.test.com.cn/test/test.asmx?wsdl');
$p = $client->__soapCall($func,array('parameters' => $params));
$result_func = $func.'Result';
return $p->$result_func;
}
报错解决了.不明觉厉.
谨记:之前一直是复制错误前面的提示去查询,一直百度不到, 遇到错,各种关键词的都搜索试试
上一篇博文:
参考文章:
解决PHP SOAP 间歇性错误 Solution: Soap WSDL Error - “failed to load external entity”
Solution: Soap WSDL Error - “failed to load external entity”