PHP和JAVA的XML-RPC中文問題解決辦法
問題描述:
在使用PHP和JAVA操作XML-RPC的時(shí)候,如果request中包含中文字符,會(huì)被自動(dòng)編碼成如下樣式:
欢欢 。
環(huán)境:PHP內(nèi)置XML-RPC的API,Apache的XML-RPC的JAVA API
PHP下的解決方法:
起初以為是中文字符的編碼問題,所以我就嘗試用各種編碼方式來(lái)編碼中文字符,然后交給string xmlrpc_encode_request ( string method, mixed params)函數(shù)來(lái)生成XML格式的請(qǐng)求,可是依然如故。百思不得其界。便操其Google 一通神搜,也沒找到解決辦法,后來(lái)我找到了http://xmlrpc-epi.sourceforge.net/這個(gè)網(wǎng)站。才知道,原來(lái)PHP文檔里給的xmlrpc_encode_request ( string method, mixed params)函數(shù)少了一個(gè)可選參數(shù)?。。?!正確的應(yīng)該是這樣的:string xmlrpc_encode_request(string method, mixed params [, array output_options])??!output_options的結(jié)構(gòu)如下:
$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");
原文說(shuō)明如下:
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
經(jīng)過(guò)測(cè)試關(guān)鍵是在"escaping" => array("markup")這個(gè)值上,將第三個(gè)參數(shù)傳入如下值就可以解決問題了:
$output_options = array(
"output_type" => "xml",
"verbosity" => "pretty",
"escaping" => array("markup"),
"version" => "xmlrpc",
"encoding" => "utf-8"
);
Apache JAVA XML-RPC的解決方法
找遍了Apache提供的API好像也沒有找到類似PHP那樣的第三個(gè)參數(shù),實(shí)在無(wú)奈發(fā)現(xiàn)他提供了一個(gè)Base64的類,我便只好將所有的中文字符在Client端用 Base64編碼,然后request到Server上,然后在Server端在用Base64解碼,哈哈~~~問題也能解決!不過(guò)不知道還有沒別的更好的辦法了?
誰(shuí)有更好的解決方法請(qǐng)和我聯(lián)系:
QQ:3470431
MSN:imdishui@hotmail.com
Email:wangsg@asiainfo.com
- AMFPHP php遠(yuǎn)程調(diào)用(RPC, Remote Procedure Call)工具 快速入門教程
- php xml-rpc遠(yuǎn)程調(diào)用
- PHP實(shí)現(xiàn)創(chuàng)建一個(gè)RPC服務(wù)操作示例
- php實(shí)現(xiàn)的一個(gè)簡(jiǎn)單json rpc框架實(shí)例
- ThinkPHP內(nèi)置jsonRPC的缺陷分析
- PHP采用XML-RPC構(gòu)造Web Service實(shí)例教程
- 使用PHPRPC實(shí)現(xiàn)Ajax安全登錄
- php中關(guān)于codeigniter的xmlrpc的類在進(jìn)行數(shù)據(jù)交換時(shí)的類型問題
- PHP遠(yuǎn)程調(diào)用以及RPC框架
相關(guān)文章
PHP simplexml_load_file()函數(shù)講解
今天小編就為大家分享一篇關(guān)于PHP simplexml_load_file()函數(shù)講解,小編覺得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來(lái)看看吧2019-02-02php for 循環(huán)語(yǔ)句使用方法詳細(xì)說(shuō)明
for 循環(huán)是 PHP 中最復(fù)雜的循環(huán)結(jié)構(gòu)。它的行為和 C 語(yǔ)言的相似。在PHP中使用的是執(zhí)行相同的代碼集的次數(shù)2010-05-05php preg_filter執(zhí)行一個(gè)正則表達(dá)式搜索和替換
preg_filter()等價(jià)于preg_replace() 除了它僅僅返回(可能經(jīng)過(guò)轉(zhuǎn)化)與目標(biāo)匹配的結(jié)果. 這個(gè)函數(shù)怎樣工作的更詳細(xì)信息請(qǐng)閱讀 preg_replace()文檔2012-02-02php入門學(xué)習(xí)知識(shí)點(diǎn)三 PHP上傳
PHP上傳也是php常用的功能,主要注意客戶端與服務(wù)器端的應(yīng)用,是不是比asp簡(jiǎn)單多了。2011-07-07PHP is_dir() 判斷給定文件名是否是一個(gè)目錄
PHP is_dir() 判斷給定文件名是否是一個(gè)目錄的函數(shù),需要的朋友可以參考下。2010-05-05