How to set UTF-8 encoding with XMLRPC client library

妖精的绣舞 提交于 2019-12-25 05:52:10

问题


I'm using XMLRPC client to call Adestra API services. Currently I'm having problems inserting Bosnian letters č, ć, ž, đ, š.

I configured my XMLRPC client to work with UTF-8, but still having problems. Here my code sample:

//******* LOGIN DATA*******/
$account = 'account';
$username = 'username';
$password = 'password';
$adestraCoreTable=1;


/**INITIALIZE API*****/
require_once('xmlrpc.inc');//First inlcude XMLRPC client library


//Calling Adestra API with our credentials
$xmlrpc= new xmlrpc_client("http://$account.$username:$password@new.adestra.com/api/xmlrpc");
$xmlrpc->setDebug(0);
$xmlrpc->request_charset_encoding="UTF-8";


$msg = new xmlrpcmsg(
                    "contact.search",
                    array(
                        //Set user id
                        new xmlrpcval($adestraCoreTable, "int"),
                        new xmlrpcval(
                            array(
                                "firstName"=> new xmlrpcval("Čokolada", "string"),
                            ),"struct"
                        )
                    )

                );
$response = $xmlrpc->send($msg);//Send request, and get the response

The rest of the code is parsing the $response which is not our main interest here.

As you can see, the firstName is set to Čokolada, but when I check it in Adestra, I get the value Äokolada. Obviously, there is problem in encoding.

Anyone can help?


回答1:


In xmlrpc.inc replace this

$GLOBALS['xmlrpc_internalencoding']='ISO-8859-1';

with this

$GLOBALS['xmlrpc_internalencoding']='UTF-8';


来源:https://stackoverflow.com/questions/24244996/how-to-set-utf-8-encoding-with-xmlrpc-client-library

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!