php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #28969 Wrong data encoding of special characters
Submitted: 2004-06-30 09:38 UTC Modified: 2004-08-11 08:25 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:0 of 1 (0.0%)
From: ba at esoft dot dk Assigned: dmitry (profile)
Status: Closed Package: SOAP related
PHP Version: 5.0.0RC3 OS: Linux 2.6.7-gentoo-r3
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: ba at esoft dot dk
New email:
PHP Version: OS:

 

 [2004-06-30 09:38 UTC] ba at esoft dot dk
Description:
------------
I'm using SOAP webservices and need to send special characters (danish letters in my case) in the data, it seems these letters break the SOAP parser.

Previously we have used NuSOAP for webservices, and here special letters are encoded / decoded transparantly.

Reproduce code:
---------------
class testWebservice {
	function test() {
		return "???";
	}
}

$SOAP = new SoapServer("test.wsdl");
$SOAP->setClass("testWebservice");
$SOAP->handle();


Expected result:
----------------
The returned string "???"


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-08-10 18:37 UTC] dmitry@php.net
Fixed in CVS HEAD.

By default ext/soap espect all string data in utf-8 encoding.

Now it is possible to change internal encoding with "encoding" option. It is acceptable both by SoapClient and SoapServer.

$SOAP = new SoapServer("test.wsdl", 
  array('encoding'=>'ISO-8859-1');

 [2004-08-11 08:25 UTC] ba at esoft dot dk
I will check it out.. sounds great!
 [2004-08-13 08:52 UTC] bryanguo at 21cn dot com
Hi, I tested the "encoding" option, but it doesn't work yet. In my case, I need to send/receive chinese characters in the data. So firstly I hope the SOAP data can encode with "gb2312":
$SOAP = new SoapServer("test.wsdl",array('encoding'=>'gb2312'));

Unfortunately, the return data is like below and "encoding" option is still 'UTF-8':
HTTP/1.1 200 OK
Date: Fri, 13 Aug 2004 06:42:12 GMT
Server: Apache/2.0.48 (Unix) PHP/5.0.0
X-Powered-By: PHP/5.0.0
Set-Cookie: SCP_WS_SESSIONID=635131d75dc3b040f0d96e88518fe02c; path=/
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Content-Length: 639
Connection: close
Content-Type: text/xml; charset="utf-8"

<?xml version="1.0" encoding="UTF-8"?>
   <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://xxx" xmlns:ns2="http://xxx" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
      <SOAP-ENV:Body>
         <ns1:FindDriversResponse>
            <FindDriversReturn SOAP-ENC:arrayType="ns2:Driver[0]" xsi:type="ns1:ArrayOf_tns1_Driver"/>
         </ns1:FindDriversResponse>
      </SOAP-ENV:Body>
   </SOAP-ENV:Envelope>

What's the problem?
 [2004-08-15 21:28 UTC] cdcampos at netcabo dot pt
I've checked with the current version (5.0.1) and it's working fine both in SoapClient and SoapServer.

The problem that remains is with SoapFault. It seems it's not recognizing the enconding given before to the Server or Client Class. Here is an example:

function AlteraEstado($dados) {
	if ($dados == 'GARBAGE') return new SoapFault("Server", "?edilha");
	else return array("Answer"=>"OK");
}
$server = new SoapServer("GPR.wsdl", array('encoding'=>'ISO-8859-1'));
$server->addFunction(array("AlteraEstado"));
$server->handle();

This code returns no valid XML Soap Envelope back to client (I suppose it breaks...).
 [2004-08-17 09:40 UTC] hailei at starsoftcomm dot com
server:
<?php
        function FindZipInfo($zipCode)
        {
                /*if($zipCode == 100021)
                        $str = "Beijing";
                else
                        $str = "????";
                return $str;*/
                return $zipCode;
        }

        header("charset='GB2312'");
        $server = new SoapServer("http://192.168.128.22/soap/test.wsdl", array('encoding'=>'GB2312'));
        $server->addFunction("FindZipInfo");
        $server->handle();
?>
client:<?php
        try
        {
                header("charset='GB2312'");
                $client = new SoapClient("http://192.168.128.22/soap/test.wsdl", array('encoding'=>'GB2312', 'trace' => 1));
                $result = $client->FindZipInfo("&Ouml;&ETH;&Icirc;&Auml;&frac14;??&Ntilde;??&frac14;??&Ntilde;??&frac14;??&Ntilde;??test&frac14;??&Ntilde;??&raquo;??&cedil;&iuml;&acute;&icirc;&Aacute;??");
                //echo $client->__getLastRequest();
                echo $client->__getLastResponse();
                //echo $result;
        }
        catch(SoapFault $fault)
        {
                echo "SOAP Fault: (faultcode: {$fault->faultcode}, faultstring: {$fault->faultstring})";
        }
?>
output:
<?xml version="1.0" encoding="UTF-8" ?> 
- <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://192.168.128.132/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
- <SOAP-ENV:Body>
- <ns1:FindZipInfoResponse>
  <CITY xsi:type="xsd:string">???ΔΌ???????????test????????????</CITY> 
  </ns1:FindZipInfoResponse>
  </SOAP-ENV:Body>
  </SOAP-ENV:Envelope>
~my question: why:
<?xml version="1.0" encoding="UTF-8" ?>
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 14:01:29 2024 UTC