异常:Message:SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://*****?wsdl' : failed to load external entity "http://****?wsdl"。
本地调用接口正常,放到服务器上之后,出现了500错误。try{}cache(){}:
try{
$client=new SoapClient($wsdl);
}catch(Exception $e){
echo 'Message:'.$e->getMessage();
}
抛出异常:Message:SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://*****?wsdl' : failed to load external entity "http://****?wsdl"。
首先确认,服务器PHP环境配置和本地同样。也百度了不少解决办法,都没起做用,请教了接口的开发者.NET 工程师。发给一张截图:
解决办法:$client=new SoapClient($wsdl);这句代码前添加libxml_disable_entity_loader(false); 问题就这样解决了。
查libxml_disable_entity_loader()做用:
Disable the ability to load external entities(禁用加载外部实体的能力)。
SoapClient在个人代码里面确实是外部的实体,我不由用加载外部实体的能力,就能够实例化SoapClient。问题也就天然而然的解决了。
PHP调用Web services接口实例:json
$url='http://****?wsdl';服务器
$client = new SoapClient($url);
$param = array("param1"=>$param1,"param2"=>$param2);url
方法1:
$p = $client->__soapCall('functionname',array("parameters"=>$param));
$arr= json_decode($p->functionnameResult,true); spa
方法2:code
$ret2 = $client->functionname($param);
$actjson=$ret2->functionnameResult;
$arr=json_decode($actjson,true);xml
return $arr;blog