我正在开发一个使用Nusoap发送xml数据的Web服务,这次我必须发送带有拉丁字符的数据,如'ó'。然而,当我把它放在肥皂客户端时它停止工作。以下是开发用于测试使用拉丁字符发送xml的代码的摘要。
这是正在开发的服务器代码的摘要:
include_once("nusoap/nusoap.php");
$server = new soap_server();
$server->configureWSDL("PersonImport","urn:PersonImport");
$server->register("PersonImport",array("login" => "xsd:string", 'senha' => 'xsd:string', 'fornecedor' => 'xsd:string'),array("return" => "xsd:string"),"urn:PersonImport","urn:PersonImport#PersonImport");
function PersonImport($login,$senha,$fornecedor) {
//Just for debug purposes
$return = "My login Is <b>".$login . "</b> And My senha Is <b>".$senha."</b> And My fornecedor Is <b>".$fornecedor."</b>.";
(...)(ommited code, xml parsing and response xml generation)
return $return;
}
这是客户代码的摘要:
<?php
require_once("nusoap/nusoap.php");
$client = new soapclient("example.com?wsdl");
$xml = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>";
$xml .= "<fornecedor>";
$xml .= "<NAME1>Gian</NAME1>";
$xml .= "<MCOD1>Giancarlo SA</MCOD1>";
$xml .= "<STCD1>80048303000113</STCD1>";
$xml .= "<STCD2>55670185501</STCD2>";
$xml .= "<STCD3>5508150087</STCD3>";
$xml .= "<RG>359730553</RG>";
$xml .= "<STRAS>rua itororó</STRAS>";
$xml .= "<HOUSE_NUM1>81</HOUSE_NUM1>";
$xml .= "<HOUSE_NUM2>301</HOUSE_NUM2>";
$xml .= "<ORT02>Menino Deus</ORT02>";
$xml .= "<PSTLZ>90110290</PSTLZ>";
$xml .= "<REGIO>RS</REGIO>";
$xml .= "<ORT01>Porto Alegre</ORT01>";
$xml .= "<TELF1>32335675</TELF1>";
$xml .= "<TELFX>32335675</TELFX>";
$xml .= "<SMTP_ADDR>teste@teste.com</SMTP_ADDR>";
$xml .= "<ERDAT>2016-10-04</ERDAT>";
$xml .= "<ChangeData>2016-10-04</ChangeData>";
$xml .= "<StartData>2016-10-04</StartData>";
$xml .= "<OffData>2016-10-04</OffData>";
$xml .= "</fornecedor>";
$result = $client->PersonImport("login","password", $xml);
echo $result;
该行
$xml .= "<STRAS>rua itororó</STRAS>";
有一个特殊的角色。如果我删除'ó'字符就可以了。
我尝试在xml上设置编码:
$xml = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>";
当我不得不用SimpleXML Parser解析xml时,这对我有用,但它不适用于soap。
我尝试像这样设置utf8或ISO-8859-1的页面标题:
header("Content-type:text/html; charset=UTF-8");
或:
header ('Content-type: text/html; charset=ISO-8859-1');
我试图使用htmlentities,但'ó'的实体是'&amp; o a c u t e;'具有特殊性格'&amp;'然后出现同样的问题。
函数序列化没有解决问题。
直到现在谷歌才能找到答案。
是否可以使用nusoap传递拉丁语特殊字符?必须有办法。
答案 0 :(得分:0)
看起来我找到了办法。使用CDATA我可以逃避&#39;&amp;&#39;所以我可以在字符串上使用htmlentities,如下所示:
$xml .= "<STRAS><![CDATA[".htmlentities("Rua Itororó")."]]></STRAS>";