Php call webservice Chinese garbled Solution

Source: Internet
Author: User

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

 

 


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.