Web 服务 unicode 字符显示为问号

发布于 2024-11-02 16:46:02 字数 5815 浏览 0 评论 0原文

我使用 nusoap 和客户端脚本编写了 php Web 服务。当我通过 php 客户端获取数据库记录时,unicode 记录显示为 ????????? ???? ????(“问号”)。

server.php

<?php

    //call library
    require_once 'config.php';
    include_once("nusoap/lib/nusoap.php");

    $conn = new Dbconn(HOST, DB, USER, PASS);

    //using soap_server to create server object
    $server = new soap_server;


    $server->soap_defencoding = 'UTF-8';
    $server->decode_utf8 = true;
    //register a function that works on server

    $server->configureWSDL('designationdivisionwsdl', 'urn:designationdivisionwsdl');
    // Register the method to expose
    //$server->register('getallbook',                // method name
    //    array('name' => 'xsd:string'),        // input parameters
    //    array('return' => 'xsd:string'),      // output parameters
    //    'urn:hellowsdl',                      // namespace
    //    'urn:hellowsdl#hello',                // soapaction
    //    'rpc',                                // style
    //    'encoded',                            // use
    //    'Says hello to the caller'            // documentation
    //);
    //
    //
    //Definimos la estructura de cada registro
    $server->wsdl->addComplexType(
            'designations',
            'complexType',
            'struct',
            'all',
            '',
            array(
                'jobtit_name' => array('name' => 'jobtit_name', 'type' => 'xsd:string'),
                'jobtit_name_si' => array('name' => 'jobtit_name_si', 'type' => 'xsd:string'),
                'jobtit_name_ta' => array('name' => 'jobtit_name_ta', 'type' => 'xsd:string')
            )
    );

    $server->wsdl->addComplexType('estructura', 'complexType', 'array', '',
            'SOAP-ENC:Array', array(),
            array(array('ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:designations[]')),
            'tns:designations');

    $server->register('getDesignations', array(), array('return' => 'tns:estructura'));

    // create the function

    function getDesignations() {

        $ssql_ = mysql_query("select jobtit_name, jobtit_name_si, jobtit_name_ta from hs_hr_job_title") or die(mysql_error());
        $numrows = mysql_num_rows($ssql_);
        $designationList = array();
        for ($x = 0; $x < $numrows; $x++) {
            $designationList[] = mysql_fetch_array($ssql_);
        }
        return $designationList;
    }

    //start getDivisionlist webMethod

    $server->wsdl->addComplexType(
            'divisions',
            'complexType',
            'struct',
            'all',
            '',
            array(
                'comp_code' => array('comp_code' => 'comp_code', 'type' => 'xsd:string'),
                'title' => array('title' => 'title', 'type' => 'xsd:string'),
                'title_si' => array('title_si' => 'title_si', 'type' => 'xsd:string'),
                'title_ta' => array('title_ta' => 'title_ta', 'type' => 'xsd:string'),
            )
    );

    $server->wsdl->addComplexType('divisiontype', 'complexType', 'array', '',
            'SOAP-ENC:Array', array(),
            array(array('ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:divisions[]')),
            'tns:divisions');

    $server->register('getDivisions', array(), array('return' => 'tns:divisiontype'));

    function getDivisions() {

        $ssql_ = mysql_query("select title, title_si, title_ta from  hs_hr_compstructtree") or die(mysql_error());
        $numrows = mysql_num_rows($ssql_);
        $divisionList = array();
        for ($x = 0; $x < $numrows; $x++) {
            $divisionList[] = mysql_fetch_array($ssql_);
        }
        return $divisionList;
    }

    // create HTTP listener
    $server->service($HTTP_RAW_POST_DATA);

    exit();
?>

client.php

<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" >
</head>
<body>
<?php
include_once("nusoap/lib/nusoap.php");
ini_set ('soap.wsdl_cache_enabled', 0);

$client = new nusoap_client('http://localhost/esamwebservice/server.php?wsdl');

//$response = $client->call('getDesignations');
$client->soap_defencoding = 'UTF-8';
$client->decode_utf8 = true;
$response = $client->call('getDivisions');
print_r($response);die;


?>
</body>
</html>

输出

Array ( [0] => Array ( [title] => The Government of Sri Lanka [title_si] => ????? ???? ???????????????? ???????? ????? [title_ta] => ?????? ?????? ??????? ???????? ) [1] => Array ( [title] => IT Department ) [2] => Array ( [title] => PHP [title_si] => PHP_si [title_ta] => ???? ? ?? ? ) [3] => Array ( [title] => Land Section [title_si] => ???? ????? [title_ta] => ??? ? ? ) [4] => Array ( [title] => sdfsdf [title_si] => dsafsda [title_ta] => fasdfasdghd ) [5] => Array ( [title] => dfsdfdf ) [6] => Array ( [title] => dsfsdfdsf ) [7] => Array ( [title] => sdfsdfsd [title_si] => ???? ????? ) [8] => Array ( [title] => IT Department two [title_si] => dfgfd [title_ta] => gdfgfd ) [9] => Array ( [title] => fg ) [10] => Array ( [title] => Western Province [title_si] => Western Province_si [title_ta] => Western Province_ta ) [11] => Array ( [title] => 456 ) [12] => Array ( [title] => Test ) [13] => Array ( [title] => asdasd ) [14] => Array ( [title] => asd ) [15] => Array ( [title] => fsdfsd ) [16] => Array ( [title] => sdfsdf [title_si] => sdfsd [title_ta] => fsdf ) )

I wrote php web service using nusoap and client script. When I fetch the database records via php client unicode records are displaying as ?????????? ???? ???? ("questions marks").

server.php

<?php

    //call library
    require_once 'config.php';
    include_once("nusoap/lib/nusoap.php");

    $conn = new Dbconn(HOST, DB, USER, PASS);

    //using soap_server to create server object
    $server = new soap_server;


    $server->soap_defencoding = 'UTF-8';
    $server->decode_utf8 = true;
    //register a function that works on server

    $server->configureWSDL('designationdivisionwsdl', 'urn:designationdivisionwsdl');
    // Register the method to expose
    //$server->register('getallbook',                // method name
    //    array('name' => 'xsd:string'),        // input parameters
    //    array('return' => 'xsd:string'),      // output parameters
    //    'urn:hellowsdl',                      // namespace
    //    'urn:hellowsdl#hello',                // soapaction
    //    'rpc',                                // style
    //    'encoded',                            // use
    //    'Says hello to the caller'            // documentation
    //);
    //
    //
    //Definimos la estructura de cada registro
    $server->wsdl->addComplexType(
            'designations',
            'complexType',
            'struct',
            'all',
            '',
            array(
                'jobtit_name' => array('name' => 'jobtit_name', 'type' => 'xsd:string'),
                'jobtit_name_si' => array('name' => 'jobtit_name_si', 'type' => 'xsd:string'),
                'jobtit_name_ta' => array('name' => 'jobtit_name_ta', 'type' => 'xsd:string')
            )
    );

    $server->wsdl->addComplexType('estructura', 'complexType', 'array', '',
            'SOAP-ENC:Array', array(),
            array(array('ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:designations[]')),
            'tns:designations');

    $server->register('getDesignations', array(), array('return' => 'tns:estructura'));

    // create the function

    function getDesignations() {

        $ssql_ = mysql_query("select jobtit_name, jobtit_name_si, jobtit_name_ta from hs_hr_job_title") or die(mysql_error());
        $numrows = mysql_num_rows($ssql_);
        $designationList = array();
        for ($x = 0; $x < $numrows; $x++) {
            $designationList[] = mysql_fetch_array($ssql_);
        }
        return $designationList;
    }

    //start getDivisionlist webMethod

    $server->wsdl->addComplexType(
            'divisions',
            'complexType',
            'struct',
            'all',
            '',
            array(
                'comp_code' => array('comp_code' => 'comp_code', 'type' => 'xsd:string'),
                'title' => array('title' => 'title', 'type' => 'xsd:string'),
                'title_si' => array('title_si' => 'title_si', 'type' => 'xsd:string'),
                'title_ta' => array('title_ta' => 'title_ta', 'type' => 'xsd:string'),
            )
    );

    $server->wsdl->addComplexType('divisiontype', 'complexType', 'array', '',
            'SOAP-ENC:Array', array(),
            array(array('ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:divisions[]')),
            'tns:divisions');

    $server->register('getDivisions', array(), array('return' => 'tns:divisiontype'));

    function getDivisions() {

        $ssql_ = mysql_query("select title, title_si, title_ta from  hs_hr_compstructtree") or die(mysql_error());
        $numrows = mysql_num_rows($ssql_);
        $divisionList = array();
        for ($x = 0; $x < $numrows; $x++) {
            $divisionList[] = mysql_fetch_array($ssql_);
        }
        return $divisionList;
    }

    // create HTTP listener
    $server->service($HTTP_RAW_POST_DATA);

    exit();
?>

client.php

<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" >
</head>
<body>
<?php
include_once("nusoap/lib/nusoap.php");
ini_set ('soap.wsdl_cache_enabled', 0);

$client = new nusoap_client('http://localhost/esamwebservice/server.php?wsdl');

//$response = $client->call('getDesignations');
$client->soap_defencoding = 'UTF-8';
$client->decode_utf8 = true;
$response = $client->call('getDivisions');
print_r($response);die;


?>
</body>
</html>

output

Array ( [0] => Array ( [title] => The Government of Sri Lanka [title_si] => ????? ???? ???????????????? ???????? ????? [title_ta] => ?????? ?????? ??????? ???????? ) [1] => Array ( [title] => IT Department ) [2] => Array ( [title] => PHP [title_si] => PHP_si [title_ta] => ???? ? ?? ? ) [3] => Array ( [title] => Land Section [title_si] => ???? ????? [title_ta] => ??? ? ? ) [4] => Array ( [title] => sdfsdf [title_si] => dsafsda [title_ta] => fasdfasdghd ) [5] => Array ( [title] => dfsdfdf ) [6] => Array ( [title] => dsfsdfdsf ) [7] => Array ( [title] => sdfsdfsd [title_si] => ???? ????? ) [8] => Array ( [title] => IT Department two [title_si] => dfgfd [title_ta] => gdfgfd ) [9] => Array ( [title] => fg ) [10] => Array ( [title] => Western Province [title_si] => Western Province_si [title_ta] => Western Province_ta ) [11] => Array ( [title] => 456 ) [12] => Array ( [title] => Test ) [13] => Array ( [title] => asdasd ) [14] => Array ( [title] => asd ) [15] => Array ( [title] => fsdfsd ) [16] => Array ( [title] => sdfsdf [title_si] => sdfsd [title_ta] => fsdf ) )

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

冰雪之触 2024-11-09 16:46:02

使用

$client->decode_utf8 = false;

而不是

$client->decode_utf8 = true;

对我有用。

Using

$client->decode_utf8 = false;

instead of

$client->decode_utf8 = true;

worked for me.

围归者 2024-11-09 16:46:02

在 server.php 文件中使用:

$server->soap_defencoding = 'UTF-8';
$server->decode_utf8 = false;
$server->encode_utf8 = true;

代替

$server->soap_defencoding = 'UTF-8';
$server->decode_utf8 = true;

: 可以解决问题。

Using:

$server->soap_defencoding = 'UTF-8';
$server->decode_utf8 = false;
$server->encode_utf8 = true;

instead:

$server->soap_defencoding = 'UTF-8';
$server->decode_utf8 = true;

in server.php file, will solve the problem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文