SOAP-错误:编码:字符串...不是有效的 utf-8 字符串
您好,我有一个使用 Zend Framework 构建的 Web 服务。其中一种方法旨在发送有关订单的详细信息。我遇到了一些编码问题。返回的值之一包含以下内容:
Jaime Torres Bodet #322-A Col. Lomas de Santa María
Web 服务返回以下错误:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Body>
<SOAP-ENV:Fault>
<faultcode>SOAP-ENV:Server</faultcode>
<faultstring>SOAP-ERROR: Encoding: string 'Jaime Torres Bodet #322-A Col. Lomas de Santa Mar\xc3...' is not a valid utf-8 string</faultstring>
</SOAP-ENV:Fault>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
我应该如何解决此问题?
谢谢
后续:问题是由于数据库截断了字符串造成的。该字段设置为 VARCHAR(50),并且它在编码值的中间被截断。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
更改编码设置怎么样:
服务器:
客户端:
...然后自动转换为UTF-8,我遇到了类似的问题,所以这对我有帮助,因此经过测试
What about change the encoding settings:
SERVER:
CLIENT:
... then the conversion is done automatically to UTF-8, I had the similiar problem, so this helped me, so it is tested
今天我遇到了同样的问题 - 导致该问题的代码是:
将 substr 更改为 mb_substr 似乎可以解决该问题:
Today I run into same problem - the code which caused that problem was:
changing substr to mb_substr seems to solve the issue:
问题是 í != i。在请求中使用之前,请尝试将字符串转换为 UTF-8。它可能看起来像这样:
请参阅 http://php.net/iconv
The problem is that í != i. Try to convert your string to UTF-8 before using in a request. It may look like that:
See http://php.net/iconv
上面的答案引导我尝试:
这也解决了我的错误。
参考:utf8_encode()
The answers above lead me to try:
which also resolved the error for me.
Reference: utf8_encode()
我使用 mb_convert_encoding 和 array_walk_recursive 走进我的 POST 参数,名为$params(数组)。
也许这对你有用:
I fixed a problem like this using mb_convert_encoding with array_walk_recursive to walk into my POST parameters, named $params (array).
Maybe this is useful for you:
我发现在我的情况下,问题不是字符串的编码,而是文件本身没有保存为 UTF-8。即使使用 UTF-8 编码显式保存也无济于事。
对我来说,插入带有 UTF-8 字符的注释很有效,例如
// Å
I found out that in my case not the encoding of strings was the problem but that the file itself was not saved as UTF-8. Even explicit saving with UTF-8 encoding did not help.
For me it worked to insert a comment with an UTF-8 character like
// Å