Solutions to XML-RPC Chinese problems in PHP and Java
Problem Description: when using PHP and Java to operate XML-RPC, if the request contains Chinese characters, it will be automatically encoded into the following style:
Huanhuan.
Environment: PHP built-in XML-RPC API, Apache XML-RPC Java API
Solution under PHP: at first, I thought it was the coding problem of Chinese characters, so I tried to use various coding methods to encode Chinese characters, and then handed them to string XMLRPC_ encode_ The request (string method, mixed parameters) function generates a request in XML format, but it remains the same. I can't think of its boundary. Then I used Google to search, but I couldn't find a solution. Later, I found it http://xmlrpc-epi.sourceforge.net/ This website. Just know that the XMLRPC given in the original PHP document_ encode_ Request (string method, mixed parameters) function is missing an optional parameter!!!! The correct should be: string XMLRPC_ encode_ request(string method,mixed params [,array output_options])!! output_ The structure of 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 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,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
After testing, the key is to pass the third parameter to the value of "escaping" = > array ("markup") to solve the problem:
$output_ options = array( "output_type" => "xml", "escaping" => array("markup"), "encoding" => "utf-8" );
Solution of Apache Java XML-RPC
After searching through the API provided by Apache, I don't seem to find the third parameter like PHP. I'm really helpless to find that it provides a Base64 class. I have to encode all Chinese characters with Base64 on the client side, then request to the server, and then decode with Base64 on the server side. Ha ha ~ ~ ~ the problem can also be solved! But I don't know if there's any better way?
Who has a better solution, please contact me: QQ: 3470431 MSN: imdishui@hotmail.com Email: wangsg@asiainfo.com