php NuSOAP 和内容类型
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5317858/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
NuSOAP and content type
提问by Bill
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:
无法弄清楚如何让 NuSOAP 将 UTF-8 用于内容类型。它不断吐出“ISO-8859-1”。这是我尝试过的相关代码位:
$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 硬编码的行。我错过了什么?
回答by vicTROLLA
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()).
还要确保您发送的是 utf8 编码数据,否则有点矛盾。(utf8_encode())。
回答by Jorge Olivares
using SoapClientworks 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 测试。
回答by Alejandro García
Change
改变
$soapclient->defencoding='utf-8';
to
到
$soapclient->soap_defencoding='utf-8';
回答by devran
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. 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.
它将解决您的 HTTP 标头问题。但我不确定这是否能解决任何编码问题,因为我一直在努力解决 NuSOAP 中的 UTF-8 编码问题,这不仅仅是因为 HTTP 标头。
回答by zero8
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.
仔细检查实际文件是否采用 utf-8 编码。有时问题在于实际文件及其编码通常发生在 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 更改为没有 BOM 的 utf-8 或 utf-8。
thanks.
谢谢。
回答by Kingsolmn
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
.
深入挖掘 NuSOAP 文件并找到了变量:$soap_defencoding
默认为ISO-8859-1
. 但是,在右下方的行是声明的注释版本,默认为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).
我在两个地方发现了这个:nusoap_base.php
和nusoap.php
. 我发现我的问题在我都换了之后就消失了(与两行的评论相反)。
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
:
问题:客户端抱怨响应编码为ISO-8859-1
解决方案:更改 NuSOAP 文件中的以下几行nusoap_base.php
并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';
从: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
供参考我的客户端 -> VB.NET 3.5 桌面应用程序