8

Can't figure out how to make NuSOAP use UTF-8 for a content type. it keeps spitting out "ISO-8859-1". here's the relevant code bits that I've tried:

$soapclient=new soapclient($url1,'wsdl');
$soapclient->http_encoding='utf-8';
$soapclient->defencoding='utf-8';

if($soapclient->fault){
    $retdata=$soapclient->fault;
}else{
    if($soapclient->getError()){
        $retdata=$soapclient->getError();
    }else{
                    $params=array($xmldata);
                    $retdata=$soapclient->call($doit,$params,$url1,$url2);
    }
} 

here's the request:

POST xxxxxxxxxxxx HTTP/1.0
Host: xxxxxxxxxxxxx
User-Agent: NuSOAP/0.9.5 (1.123)
Content-Type: text/xml; charset=ISO-8859-1
SOAPAction: "xxxxxxxxxxxxxxxxx"
Content-Length: 1629

I've even gone into nusoap.php and changed a couple of lines that had the ISO hard-coded in. What am I missing?

7 Answers 7

13

Try:

$soapClient->soap_defencoding = 'UTF-8';
$soapClient->decode_utf8 = false;

Also make sure you're sending utf8 encoded data, otherwise it's a bit of a contradiction. (utf8_encode()).

3
  • well, that didn't seem to make a difference.
    – Bill
    Mar 16, 2011 at 14:06
  • after working on this further, I'm still getting the same issue. I've added this: $xmldata=utf8_encode($xmldata); put this at the top of the script: header('Content-Type: text/html; charset=utf-8'); set my php.ini: default_charset = "utf-8" and still it shows as 'charset=ISO-8859-1"! What next to do?
    – Bill
    Mar 16, 2011 at 15:05
  • I spent hours and hours to find a solution. Thanks you're the man of the day. Dec 5, 2012 at 13:45
1

using SoapClient works fine for me.

Here is an example:

<?php
$client = new SoapClient(
                    "http://localhost/app/ws/index.php?ws=data&wsdl",
                    array('encoding'     => 'UTF-8',)
            );

$data = $client->__soapCall("data.getData", array(1));
?> 

Tested with PHP 5.3.3.

1

Change

$soapclient->defencoding='utf-8';

to

$soapclient->soap_defencoding='utf-8';
0
1

It seems in NuSOAP, HTTP content type is being set in two files :

class.soap_server.php

nusoap.php

First find lines in each file :

header("Content-Type: text/xml; charset=ISO-8859-1\r\n");

and replace them with

header("Content-Type: text/xml; charset=UTF-8\r\n");

It will solve your problem with HTTP headers. But I am not sure that this will solve any encoding problem since I have been struggling with UTF-8 encoding problem in NuSOAP it is not only because of HTTP Headers.

0

Here is what I ended up doing when I was faced with this problem (after a couple of days of pulling my hair out):

Went digging through the NuSOAP files and found the variable: $soap_defencoding which defaults to ISO-8859-1. However, on the line right below is a comment out version of the declaration that defaults to UTF-8.

There are two places that I found this: nusoap_base.php and nusoap.php. I found my problem went away when I had both changed over (inverse the commenting on the two lines).

Problem: Client complains that the response encoding is ISO-8859-1
Solution: Change the following lines in the NuSOAP files nusoap_base.php and nusoap.php:

from:
var $soap_defencoding = 'ISO-8859-1';
//var $soap_defencoding = 'UTF-8';
to:
//var $soap_defencoding = 'ISO-8859-1';
var $soap_defencoding = 'UTF-8';

For reference my Client -> VB.NET 3.5 desktop application

0

Double check the actual file is it is under utf-8 encoding. Sometimes the problem is the actual file and its encoding usually happens with Linux server.

Try changing the whole nusoap library and the controller and view files.

Change the file example ANSI to utf-8 or utf-8 without BOM.

thanks.

0
$client->soap_defencoding = 'UTF-8';
$client->setHTTPContentType('application/soap+xml');

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.