NuSphere Forums Forum Index
NuSphere Forums
Reply to topic
How to force UTF-8 encoding?


Joined: 29 Jun 2006
Posts: 20
Reply with quote
Hi,

when requesting the wsdl description page from my nusoap server the returned xml is ISO-8859-1 encoded. How can i force it to be returned as UTF-8?
I'm a bit clueless here.

Thanx in advance
View user's profileFind all posts by Doc OlsonSend private message
Site Admin

Joined: 13 Jul 2003
Posts: 8334
Reply with quote
there are two settings to care of in this case:
$soapclient->soap_defencoding that should be set to 'UTF-8' or 'ISO-8859-1'
decode_utf8 property that can be true or false
View user's profileFind all posts by dmitriSend private messageVisit poster's website


Joined: 29 Jun 2006
Posts: 20
Reply with quote
i assume the first suggestion depends on the client (which is not on my end). decode_utf8 is set to true here which is the standard setting. To check myself i ran the wsdl page in firefox which produced an ISO-8859-1 output.
so basically i can tell the client that the encoding depends on his setup?
View user's profileFind all posts by Doc OlsonSend private message
Site Admin

Joined: 13 Jul 2003
Posts: 8334
Reply with quote
ahh right,
I missed the point that it's server..

Server handles encoding like shown below:

Code:
         if(isset($this->headers['content-type']) && strpos($this->headers['content-type'],'=')){
            $enc = str_replace('"','',substr(strstr($this->headers["content-type"],'='),1));
            if(eregi('^(ISO-8859-1|US-ASCII|UTF-8)$',$enc)){
               $this->xml_encoding = strtoupper($enc);
            } else {
               $this->xml_encoding = 'US-ASCII';
            }
         } else {
            // should be US-ASCII for HTTP 1.0 or ISO-8859-1 for HTTP 1.1
            $this->xml_encoding = 'ISO-8859-1';
         }


So if client specifies either ISO-8859-1 or US-ASCII or UTF-8 by issuing Content-Type http header, it will be used, otherwise server falls back to ISO-8859-1.
View user's profileFind all posts by dmitriSend private messageVisit poster's website


Joined: 29 Jun 2006
Posts: 20
Reply with quote
For testing i changed the fallback branch to UTF-8, even AFTER the else part so it would definately end up with UTF-8 no matter what:
Code:

         if(isset($this->headers['content-type']) && strpos($this->headers['content-type'],'=')){
            $enc = str_replace('"','',substr(strstr($this->headers["content-type"],'='),1));
            if(eregi('^(ISO-8859-1|US-ASCII|UTF-8)$',$enc)){
               $this->xml_encoding = strtoupper($enc);
            } else {
               $this->xml_encoding = 'US-ASCII';
            }
         } else {
            // should be US-ASCII for HTTP 1.0 or ISO-8859-1 for HTTP 1.1
            //$this->xml_encoding = 'ISO-8859-1';
            // the following did not seem to have any effect...
            $this->xml_encoding = 'UTF-8';
         }
         // so i put it here so it would end up with UTF-8
         $this->xml_encoding = 'UTF-8';


but nothing helped, the xml reply still shows

Code:

<?xml version="1.0" encoding="ISO-8859-1"?>


i even replaced all occurences of
Code:

$this->xml_encoding = 'ISO-8859-1';

with
Code:

$this->xml_encoding = 'UTF-8';


to provocate another behaviour but no success Sad

btw: appreciate ur support Smile
View user's profileFind all posts by Doc OlsonSend private message


Joined: 29 Jun 2006
Posts: 20
Reply with quote
I also set soap_defencoding to UTF-8 and called the WSDL with my own nusoap client:

Code:

    /**
   * charset encoding for outgoing messages
   *
   * @var      string
   * @access   public
   */
    //var $soap_defencoding = 'ISO-8859-1';
   var $soap_defencoding = 'UTF-8';


result:

Code:

Request

POST /soap.php?wsdl HTTP/1.0
Host: soap.myserver
User-Agent: NuSOAP/0.7.2 (1.94)
Content-Type: text/xml; charset=UTF-8
SOAPAction: ""
Content-Length: 554

(...)

Response

HTTP/1.1 200 OK
Date: Thu, 17 Aug 2006 06:55:51 GMT
Server: Apache
X-Powered-By: PHP/5.1.4-0.0bpo1
Connection: close
Content-Type: text/xml; charset=ISO-8859-1
View user's profileFind all posts by Doc OlsonSend private message
Site Admin

Joined: 13 Jul 2003
Posts: 8334
Reply with quote
Maybe it will be faster, if you setup NuSphere PHPED with php debugger and step through your own and nusoap code to see how everything is handled?
I think it's not really hard. Please let me know if there are any problems with this "approach" Smile
View user's profileFind all posts by dmitriSend private messageVisit poster's website
works!!!!


Joined: 04 May 2007
Posts: 1
Reply with quote
esto funciono para mi

hay que reemplazar todas las entradas de xml_encoding como figura a continuacion:

"xml_encoding =" (sin comillas) por "xml_encoding = 'UTF-8'; //" (nuevamente, sin comillas)
View user's profileFind all posts by superluchoSend private message
How to force UTF-8 encoding?
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT - 5 Hours  
Page 1 of 1  

  
  
 Reply to topic