PHP头条
热点:

PHP和JAVA的XML-RPC中文问题解决办法


      问题描述:
      在使用php(做为现在的主流开发语言)和JAVA操作xml(标准化越来越近了)-RPC的时候,如果request中包含中文字符,会被自动编码成如下样式:

欢欢 。

      环境:php(做为现在的主流开发语言)内置xml(标准化越来越近了)-RPC的API,apache(Unix平台最流行的WEB服务器平台)的xml(标准化越来越近了)-RPC的JAVA API

      php(做为现在的主流开发语言)下的解决方法:
      起初以为是中文字符的编码问题,所以我就尝试用各种编码方式来编码中文字符,然后交给string xml(标准化越来越近了)rpc_encode_request ( string method, mixed params)函数来生成xml(标准化越来越近了)格式的请求,可是依然如故。百思不得其界。便操其Google 一通神搜,也没找到解决办法,后来我找到了http://xml(标准化越来越近了)rpc-epi.sourceforge.net/这个网站。才知道,原来php(做为现在的主流开发语言)文档里给的xml(标准化越来越近了)rpc_encode_request ( string method, mixed params)函数少了一个可选参数!!!!正确的应该是这样的:string xml(标准化越来越近了)rpc_encode_request(string method, mixed params [, array output_options])!!output_options的结构如下:

$output_options = array(
                       "output_type" => "xml(标准化越来越近了)",
                       "verbosity" => "pretty",
                       "escaping" => array("markup", "non-ascii", "non-print"),
                       "version" => "xml(标准化越来越近了)rpc",
                       "encoding" => "utf-8"
                      );
or

$output_options = array("output_type" => "php(做为现在的主流开发语言)");

原文说明如下:

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: xml(标准化越来越近了)rpc, 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), xml(标准化越来越近了)rpc

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

经过测试关键是在"escaping" => array("markup")这个值上,将第三个参数传入如下值就可以解决问题了:

$output_options = array(

www.phpzy.comtrue/phprm/32726.htmlTechArticlePHP和JAVA的XML-RPC中文问题解决办法 问题描述: 在使用php (做为现在的主流开发语言) 和JAVA操作xml (标准化越来越近了) -RPC的时候,如果request中包含中文字符,会被自动编码成如下样式:...

相关文章

    暂无相关文章

PHP之友评论

今天推荐