导航:业界 | 认证 | 工具 | 图形 | 技术 | 系统 | 网络 | 办公 | 网页 | 文摘 | 动画
您当前的位置:diva8.com -> I T -> 技术 -> PHP学院 -> I T内容
栏目导航
· .Net专栏 · Script
· ASP学院 · PHP学院
· Web服务器 · CGI学院
· XML学院 · SQL学院
· JSP学院 · SMS学院
热门I T
· [组图] 音频后期处理Adobe ...
· [组图] Photoshop--照片处理...
· [组图] 廉颇老矣?IE7.0 Bet...
· [图文] DuDu下载加速器推出...
· [组图] 清晰还原!Photoshop...
· [组图] 用photoshop给图片祛...
· [组图] DuDu 下载加速器试用...
· [组图] 新春特别版:PPLIVE...
· [图文] 让查找更方便些 腾讯...
· [组图] 廉颇老矣?IE7.0 Bet...
相关I T
· Ghost使用不当数据丢...
· [图文] 复制文件出错的解决...
· 经典故障 光驱丢失的...
· php和asp对象的等价...
· IIS5 HTTP500内部错...
· 企业局域网网速减慢...
· FSO 安全隐患解决办...
· Microsoft Windows ...
· 无图像、无声音、图...
· Web开发中常见的安全...
PHP和JAVA的XML-RPC中文问题解决办法
作者:admin  来源:齐昌网络  发布时间:2005-4-3 15:46:36  发布人:qichang

减小字体 增大字体


      问题描述:
      在使用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",
                       "escaping" => 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 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

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

$output_options = array(
                       "output_type" => "xml",
                       "verbosity" => "pretty",
                       "escaping" => array("markup"),
                       "version" => "xmlrpc",
                       "encoding" => "utf-8"
                      );


      Apache JAVA XML-RPC的解决方法

     找遍了Apache提供的API好像也没有找到类似PHP那样的第三个参数,实在无奈发现他提供了一个Base64的类,我便只好将所有的中文字符在Client端用 Base64编码,然后request到Server上,然后在Server端在用Base64解码,哈哈~~~问题也能解决!不过不知道还有没别的更好的办法了?

     谁有更好的解决方法请和我联系:
     QQ:3470431
     MSN:imdishui@hotmail.com
     Email:wangsg@asiainfo.com



[] [返回上一页] [打 印] [收 藏]
∷相关I T评论∷    (评论内容只代表网友观点,与本站立场无关!) [更多评论...]
关于本站 - 网站帮助 - 广告合作 - 下载声明 - 友情连接 - 网站地图 - 在线人数:
diva8.com Copyright © 2001-2006 diva8.com All Rights Reserved .粤ICP备05014750号