異常: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