As a result of work needs, help my colleague a TAO test.. net webservice application in PHP. so I began to search for information online and found that many php tutorials er uses nusoap. download one. use its own example to modify it. you can find it in the attachment after the article.
The Code is as follows:
<? Php
Require_once ('../nusoap/lib/nusoap. php ');
$ Client = new soapclient ('HTTP: // localhost/TestService/Service1.asmx? WSDL ', true );
$ Err = $ client-> getError ();
If ($ err ){
Echo '}
// Doc/parameter parameters get wrapped
$ Param = array ('str' => 'China ');
$ Result = $ client-> call ('helloworld', array ('parameters '=> $ param), '','', false, true, 'document ', 'encoded ');
// Check for a fault
If ($ client-> fault ){
Echo 'Print_r ($ result );
Echo '</pre> ';
} Else {
// Check for errors
$ Err = $ client-> getError ();
If ($ err ){
// Display the error
Echo '} Else {
// Display the result
Echo 'Print_r ($ result );
Echo '</pre> ';
}
}
Echo 'Echo 'Echo '?>
If the content returned by my webservice does not contain Chinese characters, the above example will be successful. however, a new problem occurs. If my webservice contains Chinese characters, the returned value will become garbled. the result of response is correct. it should have occurred when processing with nusoap.
Because I have not installed the PHP breakpoint debugging tool (I don't know if it is available ). therefore, only one method can be used. after reading it for one day, I finally finished reading it. changed nusoap. php is okay.
Change:
Var $ soap_defencoding = 'utf-8 ';
Var $ decode_utf8 = false;
========================================================== ====================================
It can also be changed, but the encoding must be specified during the call.
$ Client = new soapclient ('HTTP: // localhost/TestService/Service1.asmx? WSDL ', true );
$ Client-> soap_defencoding = 'utf-8 ';
$ Client-> soap_defencoding = 'utf-8 ';
The same effect is achieved.
========================================================== ====================================
If the parameters in the request contain Chinese characters, you only need to transmit the parameters in post or get mode.
If you need to write parameters with Chinese characters in the code, you need to convert the encoding to UTF8. you may refer to the attachment.
Attachment:
Nusoap Source: http://www.cnblogs.com/Files/coolstr/nusoap.zip
Various encoding conversion source files: http://www.cnblogs.com/Files/coolstr/chinese.zip