PHP and JAVA XML-RPC Chinese problem solution, read the PHP and JAVA XML-RPC Chinese problem solution, problem description: when using PHP and JAVA to operate the XML-RPC, if the request contains Chinese characters, it is automatically encoded as follows: #27426; #27426 ;. Environment: PHP built-in XML-RPC API, Apa... "> <L
Problem description:
When you use PHP and JAVA to manipulate XML-RPC, if the request contains Chinese characters, it will be automatically encoded into the following style:
Huan.
Environment: PHP built-in XML-RPC API, Apache XML-RPC JAVA API
PHP solution:
At first, I thought it was a problem of Chinese character encoding, so I tried to encode Chinese characters in various encoding methods, and then handed it to string xmlrpc_encode_request (string method, mixed params) function to generate requests in XML format. Best of mind. I tried Google to find a solution, but I found the website http://xmlrpc-epi.sourceforge.net. It is known that the xmlrpc_encode_request (string method, mixed params) function provided in the original PHP document lacks an optional parameter !!!! It should be correct: string xmlrpc_encode_request (string method, mixed params [, array output_options])! The structure of output_options is as follows:
$ Output_options = array (
"Output_type" => "xml ",
"Verbosity" => "pretty ",
"Escaping" => array ("markup", "non-ascii", "non-print "),
"Version" => "xmlrpc ",
"Encoding" => "UTF-8"
);
Or
$ Output_options = array ("output_type" => "php ");
The original text is described as follows:
Output_type: return data as either php native data types or xml encoded. ifphp is used, then the other values are ignored. default = xml
Verbosity: determine compactness of generated xml. options are no_white_space, newlines_only, and pretty. default = pretty
Escaping: determine how/whether to escape certain characters. 1 or more values are allowed. if multiple, they need to be specified as a sub-array. options are: cdata, non-ascii, non-print, and markup. default = non-ascii, non-print, markup
Version: version of xml vocabulary to use. currently, three are supported: xmlrpc, soap 1.1, and simple. the keyword auto is also recognized to mean respond in whichever version the request came in. default = auto (when applicable), xmlrpc
Encoding: the encoding that the data is in. Since PHP defaults to ISO-8859-1 you will usually want to use that. Change it if you know what you are doing. default = iso-8859-1
The key to the test is to pass the third parameter into the following value on the value of "escaping" => array ("markup") to solve the problem:
$ Output_options = array (
"Output_type" => "xml ",
"Verbosity" => "pretty ",
"Escaping" => array ("markup "),
"Version" => "xmlrpc ",
"Encoding" => "UTF-8"
);
The solution of Apache JAVA XML-RPC
After searching for the APIs provided by Apache, it seems that no third parameter like PHP has been found. it is helpless to find that it provides a Base64 class, I had to use Base64 encoding for all Chinese characters on the Client side, request to the Server, and then use Base64 decoding on the Server side ~~~ The problem can also be solved! But I don't know if there are any better solutions?
Please contact me for a better solution:
QQ: 3470431
MSN: imdishui@hotmail.com
Email: wangsg@asiainfo.com