问题描述:
在使用php和java操作xml-rpc的时候,如果request中包含中文字符,会被自动编码成如下样式:
欢欢 高考必刷卷。
环境:php内置xml-rpc的api,apache的xml-rpc的java api
php下的解决方法:
起初以为是中文字符的编码问题,所以我就尝试用各种编码方式来编码中文字符,然后交给string xmlrpc_encode_request ( string method, mixed params)函数来生成xml格式的请求,可是依然如故。百思不得其界。便操其google 一通神搜,也没找到解决办法,后来我找到了http://xmlrpc-epi.sourceforge.net/这个网站。才知道,原来php文档里给的xmlrpc_encode_request ( string method, mixed params)函数少了一个可选参数!!!!正确的应该是这样的:string xmlrpc_encode_request(string method, mixed params [, array output_options])!!output_options的结构如下:
$output_options = array(
“output_type” => “xml”,
“verbosity” => “pretty”,
“escapin石蜡燃烧的化学方程式g” => array(“markup”, “non-ascii”, “non-print”),
“version” => “xmlrpc”,
“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 ud, 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 u. currently, three are supported: xmlrpc, soap 1.1, and simple. the keyword auto is also recognized t高考文言文o me克雷洛夫寓言故事有哪些an 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 u that. change it if you know what you are doing. default=iso-8859-1
经过测试关键是在”escaping” => array(“markup”)这个值上,将第三个参数传入如下值就可以解决问题了:
$output_options = array(
“output_type” => “xml”,
“verbosity” => “pretty”,
“escaping” => array(“markup”),
“version” => “xmlrpc”,
“encoding” =&g女屌丝什么意思t; “utf-8”
);
apache java xml-rpc的解决方法
找遍了apache提供的api好像也没有找到类似php那样的第三个参数,实在无奈发现他提供了一个ba64的类,我便只好将所有的中文字符在client端用 ba64编码,然后request到rver上,然后在rver端在用ba64解码,哈哈~~~问题也能解决!不过不知道还有没别的更好的办法了?
谁有更好的解决方法请和我联系:
qq:3470431
msn:imdishui@hotmail.com
email:wangsg@asiainfo.com
本文发布于:2023-04-07 04:10:09,感谢您对本站的认可!
本文链接:https://www.wtabcd.cn/fanwen/zuowen/c108fcf17b0480bdef9e54b550db4ecf.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文word下载地址:PHP和JAVA的XML.doc
本文 PDF 下载地址:PHP和JAVA的XML.pdf
留言与评论(共有 0 条评论) |