NuSOAP and content type

こ雲淡風輕ζ 提交于 2019-12-05 05:37:05

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

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.

Change

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

to

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

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.

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

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.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!