如何使用XMLRPC客户端库设置UTF-8编码 [英] How to set UTF-8 encoding with XMLRPC client library

查看:226
本文介绍了如何使用XMLRPC客户端库设置UTF-8编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用XMLRPC客户端来调用Adestra API服务.目前,我在插入波斯尼亚字母č,ć,ž,đ,š时遇到问题.

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

我将XMLRPC客户端配置为与UTF-8一起使用,但是仍然有问题.这是我的代码示例:

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

其余代码将解析$ response,这不是我们的主要兴趣所在.

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

如您所见,firstName设置为Čokolada,但是当我在Adestra中对其进行检查时,得到的值是Äokolada.显然,编码存在问题.

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.

任何人都可以帮忙吗?

推荐答案

在xmlrpc.inc中替换此

In xmlrpc.inc replace this

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

与此

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

这篇关于如何使用XMLRPC客户端库设置UTF-8编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆