Encoding of WebService calls on the GBK page in PHP: XML error parsing SOAP payload on line 1

Source: Internet
Author: User

WebService, which must be familiar to everyone, is a way for the "service provider" to provide services to the "service caller. There are several key technologies:

    1. XML: Standard Method for describing data
    2. Soap: Simple Object Access Protocol for information exchange
    3. WSDL: Web Service Description Language
    4. UDDI: Universal Description, discovery, and integration. It is a platform-independent, XML-based protocol used to describe commerce on the Internet.

By default, soap transmits UTF-8 encoding, which also determines that WebService uses UTF-8 encoding by default.

Currently, the maintained Project is a PHP project, and the encoding is all using GBK. When you call the WebService method provided by yourself, you will encounter Encoding Problems. The PHP page calls WebService, which calls another PHP class that calls the COM component. This is probably the case.

 
  PHP page (GBK)->WebService (UTF-8)->PHP class (GBK)

Before you encounter any problems, everything was calm, and it took many years. One day, the company acquired other companies. In order to integrate services, user information was also integrated. The accounts of all users of the original company were composed of English characters and numbers, the acquired company has not made such a limit, and the account has Chinese characters. After integration, the problem occurs. "error in MSG parsing: XML error parsing SOAP payload on Line 1: Invalid character [detail]"!

PHP is not very familiar with it just recently, and the debugging of netbeans is often poor. So open vs, reference WebService, and start testing. Returned results, can not find the user, and is garbled, OK, after a look, because the WebService UTF-8 encoding to PhP class, encoding inconsistency caused! Convert to GBK and pass it back. After receiving the data, find the user, but garbled. After converting the returned data to the UTF-8 again, everything is OK! Test everything in! On the testing machine! Start testing! Garbled characters are displayed! Still "error in MSG parsing: XML error parsing SOAP payload on Line 1: Invalid character [detail!

Calm down and continue the analysis! It should be caused by WebService calls on the PHP page! The test page below vs is UTF-8 and there is no problem between them, but this page of PHP is GBK. After the change, everything becomes calm again.

   code highlighting produced by actipro codehighlighter (freeware) 
http://www.CodeHighlighter.com/
--> call: PHP page, convert the parameter to UTF - 8 -> WebService, after converting to GBK -> PHP class
return: PhP class -> WebService, after receiving the message, convert it to UTF - 8 -> PHP page, converted to GBK

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.