为什么 Web 服务不支持重音字母?
我将 wsdl
文件中返回值的 datatype
设置为 xsd:anyType
:
<message name="getEtapeProspResponse">
<part name="return" type="xsd:anyType"/>
</message>
PHP
函数webservice
调用返回一个字符串,该字符串是根据 MySQL 表中选定的列构造的。其中一列的 datatype
为 text
:
function getEtapeProsp($user,$motpasse)
{
$user_code = verifyUser($user, $motpasse) ;
$resultat="";
if ( $user_code != null)
{
$datejour = date("Y-m-d");
$connec = mysql_connect("192.168.1.123:3306", "root", "mysqlroot");
mysql_select_db("finance",$connec);
$query = mysql_query("SELECT * FROM etape_prospection INNER JOIN type_prospection ON etape_prospection.type_prosp_id = type_prospection.type_prosp_id WHERE prosp_id IN (SELECT prosp_id FROM transfert WHERE user_code ='".$user_code ."' AND date_transfert='".$datejour."') order by etape_prospection.prosp_id");
while($ligne = mysql_fetch_array($query))
{
$resultat .= $ligne['etape_prosp_id'].';';
$resultat .= $ligne['type_prosp_lib'].';';
$resultat .= convertDateFormatHH($ligne['etape_prosp_date']).';';
$resultat .= $ligne['etape_prosp_comment'].';'; // this is the text column
$resultat .= $ligne['prosp_id'].';';
$resultat .= "\r\n";
}
}
else
{
$resultat = "Login ou mot de passe incorrect" ;
}
return $resultat;
}
在数据库中,“etape_prosp_comment”的值有一个重音字母 é。 问题是,当我从 J2ME 应用程序调用 Web 服务时,会引发异常。但是,如果我不在列
中插入任何重音字母,那么网络服务就可以了。
那么如何解决这个重音字母问题呢?
I set the datatype
of the returned value in the wsdl
file to be of xsd:anyType
:
<message name="getEtapeProspResponse">
<part name="return" type="xsd:anyType"/>
</message>
The PHP
function which the webservice
calls returns a String which is constructed from the selected columns from a MySQL table. And one of the columns has a datatype
of text
:
function getEtapeProsp($user,$motpasse)
{
$user_code = verifyUser($user, $motpasse) ;
$resultat="";
if ( $user_code != null)
{
$datejour = date("Y-m-d");
$connec = mysql_connect("192.168.1.123:3306", "root", "mysqlroot");
mysql_select_db("finance",$connec);
$query = mysql_query("SELECT * FROM etape_prospection INNER JOIN type_prospection ON etape_prospection.type_prosp_id = type_prospection.type_prosp_id WHERE prosp_id IN (SELECT prosp_id FROM transfert WHERE user_code ='".$user_code ."' AND date_transfert='".$datejour."') order by etape_prospection.prosp_id");
while($ligne = mysql_fetch_array($query))
{
$resultat .= $ligne['etape_prosp_id'].';';
$resultat .= $ligne['type_prosp_lib'].';';
$resultat .= convertDateFormatHH($ligne['etape_prosp_date']).';';
$resultat .= $ligne['etape_prosp_comment'].';'; // this is the text column
$resultat .= $ligne['prosp_id'].';';
$resultat .= "\r\n";
}
}
else
{
$resultat = "Login ou mot de passe incorrect" ;
}
return $resultat;
}
In the database the value of the "etape_prosp_comment" has an accentuated letter , é.
The problem is that when I call the webservice from my J2ME
application then an exception is thrown. But if I don't insert any accentuated letters in the column
then the webservice is ok.
So how to resolve this accentuated letters problem ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
文本包含字符,如a、b、c、d、e 或é(在您的情况下)等。系统支持的所有字符一起形成字符集。然后,字符编码定义如何将字符序列化为字节表示形式(什么值,该值将存储多少字节等)。
这就是编码中出现问题的地方。您的字符被转换为字节,然后您必须从字节中取回字符。如果Web服务和客户端不使用相同的字符编码,则Web服务无法将来自客户端的字节转换为字符,反之亦然;您将收到错误或格式错误的字符串。
我不是 PHP 开发人员,但以下文章包含一些有关解决该问题的相关信息: 字符集/ 字符编码问题。
那篇文章引用了另一篇关于字符集的好文章(虽然有点旧,从 2003 年开始):The Absolute Maximum Every软件开发人员绝对必须了解 Unicode 和字符集(没有任何借口!),因此请务必先阅读本文。
您应该选择的编码是 UTF-8,主要是因为这是 Web 服务互操作性指南强制要求的编码,以及 UTF-16; 请参阅基本配置文件的规则 R1012 。
Text contains characters like a, b, c, d, e or é (in your case) etc. All characters that a system supports form together a character set. A character encoding then defines how a character is serialized into a byte representation (what value, how many bytes will the value be stored in etc).
This is where you get the problem, in the encoding. Your characters get transformed to bytes and then from the bytes you have to get back the characters. If the web service and the client do not use the same character encoding, the web service can not convert the bytes from the client into characters, and vice-versa; you will either get errors or malformed character strings.
I'm not a PHP developer, but the following article contains some pertinent information about addressing the issue: Character Sets / Character Encoding Issues.
That article references another good one about character sets (although a bit old, from 2003): The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!), so make sure you read this first.
The encoding you should be going for is UTF-8, mainly because that's the encoding mandated by the web service interoperability guide, along with UTF-16; see rule R1012 of the Basic Profile.