通过 Java Web 服务发送阿拉伯文本

发布于 2025-01-04 14:53:05 字数 1090 浏览 1 评论 0原文

当我通过 JAVA Web 服务发送阿拉伯文本时,我的手机上出现特殊字符(??????)。以下是我如何实施的原因。

  1. Webservice 客户端和测试程序位于我的 Windows PC 上,我从 Eclipse 运行,其字符集为 ISO-8859-1。
  2. 在我的测试程序中,我将阿拉伯字符串编码(使用 URLEncoder)为 ISO-8859-6。
  3. WebService Host安装在Linux服务器上。这里我将编码的字符串转换为字节。然后我通过 TCP IP 将此请求转发到 java 服务。该服务负责发送短信。
  4. 在此 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.

  1. Webservice Client and Test program is on my windows PC and I am running from Eclipse whose char set is ISO-8859-1.
  2. In my Test Program I am encoding (using URLEncoder) the Arabic String to ISO-8859-6.
  3. 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.
  4. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

柒七 2025-01-11 14:53:06

我认为问题出在您的 sendmessagetoProvider 以及 URLEncoderURLDecoder 的使用中。

当您发送消息时,您可能必须对其进行编码。您正在客户端调用 decode 。顺便说一句,恕我直言,这就是您收到“特殊字符”的原因。

因此,首先查看您的 API 规范。 sendmessagetoProvider 方法期望什么?也许您不必将字符串编码为 URL?可能它只支持 Unicode,或者您在调用客户端时必须提供编码?然后相应地修复您的代码。

祝你好运。

I think that the problem is somewhere into your sendmessagetoProvider as well as in usage for URLEncoder and URLDecoder.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文