简体   繁体   English

NuSOAP 和内容类型

[英]NuSOAP and content type

Can't figure out how to make NuSOAP use UTF-8 for a content type.无法弄清楚如何让 NuSOAP 使用 UTF-8 作为内容类型。 it keeps spitting out "ISO-8859-1".它不断吐出“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?我什至进入了 nusoap.php 并更改了几行硬编码 ISO 的行。我错过了什么?

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 编码数据,否则会有点矛盾。 (utf8_encode()). (utf8_encode())。

Change改变

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

to

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

It seems in NuSOAP, HTTP content type is being set in two files :在 NuSOAP 中,似乎在两个文件中设置了 HTTP 内容类型:

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.它将解决您的 HTTP 标头问题。 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.但我不确定这是否能解决任何编码问题,因为我一直在努力解决 NuSOAP 中的 UTF-8 编码问题,这不仅仅是因为 HTTP 标头。

using SoapClient works fine for me.使用SoapClient对我来说很好。

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.使用 PHP 5.3.3 测试。

Double check the actual file is it is under utf-8 encoding.仔细检查实际文件是否采用 utf-8 编码。 Sometimes the problem is the actual file and its encoding usually happens with Linux server.有时问题出在实际文件上,它的编码通常发生在 Linux 服务器上。

Try changing the whole nusoap library and the controller and view files.尝试更改整个 nusoap 库以及控制器和视图文件。

Change the file example ANSI to utf-8 or utf-8 without BOM.将文件示例 ANSI 更改为 utf-8 或不带 BOM 的 utf-8。

thanks.谢谢。

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

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 .挖掘 NuSOAP 文件并找到变量: $soap_defencoding默认为ISO-8859-1 However, on the line right below is a comment out version of the declaration that defaults to UTF-8 .但是,在右下一行是默认为UTF-8的声明的注释版本。

There are two places that I found this: nusoap_base.php and nusoap.php .我在两个地方找到了这个: nusoap_base.phpnusoap.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问题:客户抱怨响应编码是ISO-8859-1
Solution: Change the following lines in the NuSOAP files nusoap_base.php and nusoap.php :解决方案:更改 NuSOAP 文件nusoap_base.phpnusoap.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供参考我的客户端 - > VB.NET 3.5 桌面应用程序

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM