PHP XML error parsing SOAP payload on line 1

  • 2020-03-31 20:53:46
  • OfStack

Webservices, which you are probably familiar with, are a way for a service provider to provide a service to a service caller. There are a few key techniques:

XML: a standard way to describe data
SOAP: simple object access protocol for information exchange
WSDL: Web services description language
UDDI: universal description, discovery, and integration, a platform-independent, xml-based protocol for describing business on the Internet.

SOAP by default transmits utf-8 encoding, which determines that WebService also USES utf-8 encoding by default.

The project being maintained now is a PHP project, all coded with GBK, and you will encounter coding problems when you call the WebService method provided by yourself. A PHP page calls a WebService, which in turn calls another PHP class that calls a COM component. So that's sort of the scene.
 
PHP Page ( GBK )  -> WebService ( UTF-8 )  -> PHP Class ( GBK )  

Before the problem, everything was calm, and so on for many years. One day, the company acquired other companies, in order to integrate the service, the user information is also integrated together, the original company all user accounts are composed of English characters and Numbers, and the acquisition of this company did not make such restrictions, the account has Chinese characters. After the integration, the problem appeared, "error in MSG parsing: XML error parsing SOAP payload on line 1: Invalid character [detail]"!

PHP is new, not very familiar, and NetBeans debugging is often difficult. So open VS, refer to WebService, and start testing. Return the result, can not find the user, and is messy code, OK, after a look, because WebService utf-8 encoding to the PHP class, encoding inconsistency caused by! Convert to GBK and then the past, received data, find the user, but still garbled code. After converting the returned data to utf-8 again, everything is OK! VS test everything is ok! Go to the test machine! Start testing! Open it, garbled! Error in MSG parsing: XML error parsing SOAP payload on line 1: Invalid character [detail]

Calm down, continue to analyze! This should be caused when a PHP page calls a WebService! The test page below VS is utf-8, there is no problem between them, but the PHP page is GBK. After the revision, everything was calm again.
 
 Call: PHP Page, the parameter is converted to UTF-8 -> WebService Converting, GBK after  -> PHP class  
 Returns: PHP class  -> WebService After receiving, convert to UTF-8 -> PHP Page, convert to GBK 

Related articles: