3

I am trying to send arabic sms (or french sms) from kannel and it does not get the client end perfectly ( somtimes ?????? for arabic words), after doing some analysis on the values sent between the bearebox,smsbox and smsc i found out that the error in encoding happens between my bearbox and smsbox.

I have used charset=utf-8&coding=2 on my http request for sending sms but the same problem occurs

Does anyone have any idea on what is the problem or better a solution ??

here is the code i use to send sms

StringBuffer param = new StringBuffer()
       param.append("http://localhost:1025/cgi-bin/sendsms?")
       param.append(URLEncoder.encode("username","UTF-8")).append("=").append(URLEncoder.encode("xxx","UTF-8"))
       param.append("&").append(URLEncoder.encode("password","UTF-8")).append("=").append(URLEncoder.encode("xxxx","UTF-8"))
       param.append("&").append(URLEncoder.encode("to","UTF-8")).append("=").append(URLEncoder.encode(numTel,"UTF-8"));
       param.append("&").append(URLEncoder.encode("charset","UTF-8")).append("=").append(URLEncoder.encode("utf-8","UTF-8"))

       param.append("&").append(URLEncoder.encode("coding","UTF-8")).append("=").append(URLEncoder.encode("2","UTF-8"))
       param.append("&").append(URLEncoder.encode("text","UTF-8")).append("=").append(URLEncoder.encode(text,"UTF-8"))
       param.append("&").append(URLEncoder.encode("priority","UTF-8")).append("=").append(URLEncoder.encode(""+priority,"UTF-8"))
       param.append("&").append(URLEncoder.encode("dlr-mask","UTF-8")).append("=").append(URLEncoder.encode("31","UTF-8"))
       param.append("&").append(URLEncoder.encode("dlr-url","UTF-8")).append("=").append(URLEncoder.encode(urlString,"UTF-8"))
       try{
           URL url = new URL(param.toString())
           System.out.println("INFO : Opening connection ")
           HttpURLConnection urlconnection = (HttpURLConnection) url.openConnection()
           System.out.println("INFO : Connection openned")
           BufferedReader input = new BufferedReader( new InputStreamReader(urlconnection.getInputStream()))
           String inputLine

           while ((inputLine = input.readLine()) != null)
               aResult.append(inputLine)
           input.close()
       }catch(Exception e){
           e.printStackTrace()
           return false
       }

       System.out.println("response : "+aResult.toString())
       System.out.println("INFO : all sent disconnect.")
'

Thank you

Saad Touhbi
  • 345
  • 1
  • 3
  • 13
  • How are you making the http request? – Carlo Apr 17 '12 at 15:26
  • check the post i added the code – Saad Touhbi Apr 17 '12 at 15:45
  • If you print param.toString() do you see the expected arab text? – Carlo Apr 17 '12 at 16:00
  • No. the text is all encoded except for the english words. Does it mean something is wrong mith my http request ?? because when i look in the smsbox console i see the expected text but when i go to the bearbox console it's messed up – Saad Touhbi Apr 17 '12 at 16:14
  • Ok, take the encoded text and try it [here](http://meyerweb.com/eric/tools/dencoder/). Do you see the expected text? – Carlo Apr 17 '12 at 17:55
  • i did what you said and after decoding it, i see the expected text. But the same problem occurs when the text goes from the smsbox and the bearbox. do you have any idea why the text gets messed up ?? – Saad Touhbi Apr 18 '12 at 09:43
  • I would try to add -Dfile.encoding=UTF-8 to the JVM parameters. But I'm almost running out of ideas. – Carlo Apr 18 '12 at 10:16
  • Or maybe you could try to sniff the traffic you're sending out, to see if it's being transmitted correctly. – Carlo Apr 18 '12 at 10:17
  • i have been able to send an utf-8 encoded sms to the virtual smsc but i am not sure if it's gonna be decoded once it gets to the client's en d!! i am using SMPPSim is there anyway to store the received sms into a file because i want to see how the sms is handeled by the smsc ?? thank you for your help – Saad Touhbi Apr 18 '12 at 11:38
  • Thanks a lot for your help :) i have been able to send arabic/french SMS with no change. i encode my text to utf-8 in my httpr request to the smsbox and i don't send a "charset" parameter in the GET i only send encoding=2, and it works !! i don't know why but it works :P if you have any idea it would be appreciated :) – Saad Touhbi Apr 18 '12 at 12:01
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/10234/discussion-between-saad-ben-and-carlo) – Saad Touhbi Apr 18 '12 at 15:27

3 Answers3

4

i have been able to send arabic/french sms with this http request example :

StringBuffer param = new StringBuffer()
       param.append("http://localhost:1025/cgi-bin/sendsms?")
       param.append(URLEncoder.encode("username","UTF-8")).append("=").append(URLEncoder.encode("xxx","UTF-8"))
       param.append("&").append(URLEncoder.encode("password","UTF-8")).append("=").append(URLEncoder.encode("xxxx","UTF-8"))
       param.append("&").append(URLEncoder.encode("to","UTF-8")).append("=").append(URLEncoder.encode(numTel,"UTF-8"));

       param.append("&").append(URLEncoder.encode("coding","UTF-8")).append("=").append(URLEncoder.encode("2","UTF-8"))
       param.append("&").append(URLEncoder.encode("text","UTF-8")).append("=").append(URLEncoder.encode(text,"UTF-8"))
       param.append("&").append(URLEncoder.encode("priority","UTF-8")).append("=").append(URLEncoder.encode(""+priority,"UTF-8"))
       param.append("&").append(URLEncoder.encode("dlr-mask","UTF-8")).append("=").append(URLEncoder.encode("31","UTF-8"))
       param.append("&").append(URLEncoder.encode("dlr-url","UTF-8")).append("=").append(URLEncoder.encode(urlString,"UTF-8"))
       try{
           URL url = new URL(param.toString())
           System.out.println("INFO : Opening connection ")
           HttpURLConnection urlconnection = (HttpURLConnection) url.openConnection()
           System.out.println("INFO : Connection openned")
           BufferedReader input = new BufferedReader( new InputStreamReader(urlconnection.getInputStream()))
           String inputLine

           while ((inputLine = input.readLine()) != null)
               aResult.append(inputLine)
           input.close()
       }catch(Exception e){
           e.printStackTrace()
           return false
       }

       System.out.println("response : "+aResult.toString())
       System.out.println("INFO : all sent disconnect.")

i don't send the "charset" parameter in my request i only send the coding parameter

Saad Touhbi
  • 345
  • 1
  • 3
  • 13
0

I've made a bit of research, and I believe that if you specify coding=2 Kannel expects the message body encoded as UTF-16, at least if I understood correctly this discussion.
Also you should have a look at this document.

Carlo
  • 1,686
  • 3
  • 29
  • 43
  • i have tried to encode my text to utf-16 before sending and specified 'coding=2' and the decoding was wrong wich means that the version of kannel that i am working on is actually expecting an utf-8 encoded text (BTW i am using kannel 1.4.3) so i will keep what you said in mind if we migrate to another version of kannel ... and Thank you for your help – Saad Touhbi Apr 18 '12 at 15:27
0

All you have to do is the following (kannel release 1.5): 1- Add alt-charset="UTF-8" under smsc group in your kannel configuration 2- when sending the sms مرحبا for example you have to type type the following in your sendsms command: text=مرحبا&charset=UTF-8&coding=1

Check your database using mysql command because database management tools like webmin may not recognize Arabic letters