通过 Java Web 服务发送阿拉伯文本
当我通过 JAVA Web 服务发送阿拉伯文本时,我的手机上出现特殊字符(??????)。以下是我如何实施的原因。
- Webservice 客户端和测试程序位于我的 Windows PC 上,我从 Eclipse 运行,其字符集为 ISO-8859-1。
- 在我的测试程序中,我将阿拉伯字符串编码(使用 URLEncoder)为 ISO-8859-6。
- WebService Host安装在Linux服务器上。这里我将编码的字符串转换为字节。然后我通过 TCP IP 将此请求转发到 java 服务。该服务负责发送短信。
- 在此 Java 服务中,我使用与上述相同的加密进行解码并发布到 SMS 提供商。
实现
/**
* Arabic Implementation is as below
**/
String message= arabictext;
message=URLEncoder.encode(message,"ISO-8859-6");
sendMessage(message,uername,password); ///webservice call
Web服务主机编码:
sendMessage(p_message,username,password){
byte[] request = message.getbytes();//tried by passing character set
Tcserver.post(request);//posting the request to java client
}
注意:Web服务主机和java客户端托管在同一台物理服务器上。
Java 客户端:
sendSMS(p_message){
message =URLDecoder.decode(p_message,"ISO-8859-6");//send message to mobile provider.
sendmessagetoProvider(message);
}
当我在 PC 上运行 TCPViewer 时,我看到特殊字符。知道如何解决这个问题。
I am getting special characters(?????) on my mobile when I send arabic text through JAVA Webservice. Below is the whay how I implemented.
- Webservice Client and Test program is on my windows PC and I am running from Eclipse whose char set is ISO-8859-1.
- In my Test Program I am encoding (using URLEncoder) the Arabic String to ISO-8859-6.
- WebService Host is Installed on Linux server. Here I am converting the encoded string to bytes. Then I am forwading this request to java service over TCP IP. This service is responsible to send SMS.
- In this Java service I am decoding with same encryption as above and posting to SMS provider.
Implementation
/**
* Arabic Implementation is as below
**/
String message= arabictext;
message=URLEncoder.encode(message,"ISO-8859-6");
sendMessage(message,uername,password); ///webservice call
Web Service Host coding:
sendMessage(p_message,username,password){
byte[] request = message.getbytes();//tried by passing character set
Tcserver.post(request);//posting the request to java client
}
Note: Both Webservice Host and java client are hosted on same physical server.
Java Client :
sendSMS(p_message){
message =URLDecoder.decode(p_message,"ISO-8859-6");//send message to mobile provider.
sendmessagetoProvider(message);
}
when I ran TCPViewer on my PC I am seeing special characters. Any idea how to fix this issue.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为问题出在您的
sendmessagetoProvider
以及URLEncoder
和URLDecoder
的使用中。当您发送消息时,您可能必须对其进行编码。您正在客户端调用
decode
。顺便说一句,恕我直言,这就是您收到“特殊字符”的原因。因此,首先查看您的 API 规范。
sendmessagetoProvider
方法期望什么?也许您不必将字符串编码为 URL?可能它只支持 Unicode,或者您在调用客户端时必须提供编码?然后相应地修复您的代码。祝你好运。
I think that the problem is somewhere into your
sendmessagetoProvider
as well as in usage forURLEncoder
andURLDecoder
.When you are sending message you probably have to encode it. You are calling
decode
at client side instead. BTW IMHO this is the reason for "special characters" you receive.So, first take a look on your API specification. What is method
sendmessagetoProvider
expecting? Probably you do not have to encode the string as URL? Probably it just supports Unicode or you have to provide the encoding when you are calling client? Then fix you code accordingly.Good luck.