来自 Web 服务的 UFT-8 阿拉伯语编码
我正在尝试对来自 Web 服务的阿拉伯文本进行编码。目前,这些值以问号 (???) 形式出现。
我读过很多博客(甚至 stackoverflow 答案/链接),但似乎没有任何效果。
知道如何解决这个问题吗?
谢谢
I am trying to encode Arabic text from a Web service. Currently the values come as question marks (???).
I have read many blogs (even stackoverflow answers/links) but nothing seems to worked.
Any idea of how I can resolve this issue?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您使用 Dreamweaver 的设计器视图并将阿拉伯文本粘贴到设计视图中,您将在 Dreamweaver 的代码视图中获得 ASCII 字符,该字符可在任何 Web 浏览器中使用。
If you use dreamweaver's designer view and paste your Arabic text in design view you will get ascii characters in dreamweaver's code view which will work in any web browser.
首先,重要的一点:检查您正在使用的网络服务是否向您发送实际的阿拉伯字符而不是实际的问号。如果不确定,请检查网络转储,并使用 wget/curl 执行简单的事务;检查结果。
如果 WS 发送的原始数据是问号,那么您将面临一场艰苦的战斗 - 再试一次并摆弄 Accept/Accept-Charset 标头。如果全部失败,可能是服务器本身编码不正确,之后您无能为力......
此外,您正在尝试解码文本,将其转换从字节表示到抽象字符。
First, an important aside: check that the web service you are consuming sends you actual Arabic characters and not actual question marks. Check a network dump if you are not sure, and use wget/curl to perform a simple transaction; check the results.
If the raw data as sent by the WS is question marks, you have an uphill battle - try again and fiddle with the Accept/Accept-Charset headers. If all fail, it may be that the server itself isn't coded properly and there ain't much you can do after that...
Also, you're trying to decode the text, convert it from a byte representation to abstract characters.
这是从 Android 发送
UTF-8
数据时出现的问题。您的代码可以正常工作,只是您必须将String
编码为Base64
。在 PHP 服务器上,您只需解码Base64
字符串即可。这对我有用。如果您需要代码我可以分享。This has been the problem Sending
UTF-8
data from Android. Your code would work fine except that you will have to encode yourString
toBase64
. At Server PHP you just decodeBase64
String back. It worked for me. I can share if you need the code.