在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
1 <?
2 /******************************************************************************/ 3 /* 文件名 : soapclient.php 4 /* 说 明 : WebService接口客户端例程 5 /******************************************************************************/ 6 include('NuSoap.php'); 7 // 创建一个soapclient对象,参数是server的WSDL 8 $client = new soapclient('http://localhost/Webservices/Service.asmx?WSDL', 'wsdl'); 9 // 参数转为数组形式传递 10 $aryPara = array('strUsername'=>'username', 'strPassword'=>MD5('password')); 11 // 调用远程函数 12 $aryResult = $client->call('login',$aryPara); 13 //echo $client->debug_str; 14 /* 15 if (!$err=$client->getError()) { 16 print_r($aryResult); 17 } else { 18 print "ERROR: $err"; 19 } 20 */ 21 $document=$client->document; 22 echo <<<SoapDocument 23 <?xml version="1.0" encoding="GB2312"?> 24 <SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:si="http://soapinterop.org/xsd"> 25 <SOAP-ENV:Body> 26 $document 27 </SOAP-ENV:Body> 28 </SOAP-ENV:Envelope> 29 SoapDocument; 30 ?>
方法二:代理方式调用
1 <?
2 /******************************************************************************/ 3 /* 文件名 : soapclient.php 4 /* 说 明 : WebService接口客户端例程 5 /******************************************************************************/ 6 require('NuSoap.php'); 7 //创建一个soapclient对象,参数是server的WSDL 8 $client=new soapclient('http://localhost/Webservices/Service.asmx?WSDL', 'wsdl'); 9 //生成proxy类 10 $proxy=$client->getProxy(); 11 //调用远程函数 12 $aryResult=$proxy->login('username',MD5('password')); 13 //echo $client->debug_str; 14 /* 15 if (!$err=$proxy->getError()) { 16 print_r($aryResult); 17 } else { 18 print "ERROR: $err"; 19 } 20 */ 21 $document=$proxy->document; 22 echo <<<SoapDocument 23 <?xml version="1.0" encoding="GB2312"?> 24 <SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:si="http://soapinterop.org/xsd"> 25 <SOAP-ENV:Body> 26 $document 27 </SOAP-ENV:Body> 28 </SOAP-ENV:Envelope> 29 SoapDocument; 30 ?>
$client->soap_defencoding = 'utf-8';
$client->xml_encoding = 'utf-8';
至此应该是一切正常了才对,但是我们在输出结果的时候,却发现返回的是乱码。 NuSoap调用WebService出现乱码的解决方法:
$client->soap_defencoding = 'utf-8';
$client->decode_utf8 = false; $client->xml_encoding = 'utf-8'; |
2022-07-18
2022-08-16
2022-11-06
2022-08-18
2022-08-15
请发表评论