Home » Php » php – NuSOAP and content type

php – NuSOAP and content type

Posted by: admin July 12, 2020 Leave a comment


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');


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?

How to&Answers:


$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()).


using SoapClient works fine for me.

Here is an example:

$client = new SoapClient(
                    array('encoding'     => 'UTF-8',)

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

Tested with PHP 5.3.3.







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



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.


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:


var $soap_defencoding = 'ISO-8859-1';

//var $soap_defencoding = 'UTF-8';


//var $soap_defencoding = 'ISO-8859-1';

var $soap_defencoding = 'UTF-8';

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


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.