Example reference of how to call webservice in PHP_PHP tutorial

WBOY
Release: 2016-07-21 15:11:50
Original
927 people have browsed it

The following is an example: the web service is to query whether QQ users are online

Develop the client using php5:

Copy the code The code is as follows:

try {
//$client = new SoapClient("HelloService.wsdl",array('encoding'=>'UTF-8'));
$client = new SoapClient("http ://webservice.webxml.com.cn/webservices/qqOnlineWebService.asmx?wsdl");
var_dump($client->__getFunctions());
print("
") ;
var_dump($client->__getTypes());
print("
");

class qqCheckOnline{
var $qqCode = "10000";
};
$arrPara = array(new qqCheckOnline);

"< ;br/>";

} catch (SOAPFault $e) {
print $e;
}
?>


The code is really simple, right? When creating a SoapClient object, you can use a WSDL file saved locally or a remote address. The following array can contain many parameters. For specific parameters, you can check the SoapClient help of php. Here is the character set encoding. If If there are Chinese characters in the parameters of the calling method, the character set encoding must be specified, otherwise an error will occur.

Before calling the web service, you can first call the __geunctions() and __getTypes() methods of SoapClient to see the methods, parameters and data types exposed by the web service you want to call. It should be noted that the parameter names passed in must be It is consistent with what is defined in soapclient, otherwise the parameters cannot be passed.
You need to use the __soapCall() or __call() method of SoapClient. For specific usage methods, you can check the PHP help documentation. If the parameter requirement is a structure, please use a class instead, such as the code above.

Another problem I found is that if the web service method returns a string in XML format, PHP will parse the data content by itself after receiving it, not the XML string.


http://www.bkjia.com/PHPjc/326793.html

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/326793.htmlTechArticleThe following is an example: the web service is to query whether QQ users are online using php5 to develop the client: Copy code code As follows: ?php try { //$client = new SoapClient("HelloSer...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template