0

I want to send sms in Hindi Language from Java based Desktop Software. Below is the code which gets the message from JTextArea and appends the message in a URL. With this code I am able to send SMS in Hindi from Macbook but the same is not working in Windows. While sending sms from windows, the characters are replaced with ?

Below is the code that gets the message from the JTextArea

byte[] utf8Bytes;
utf8Bytes = hindiSMS.getText().getBytes(StandardCharsets.UTF_8);
String hindiMessage = new String(utf8Bytes,StandardCharsets.UTF_8);
hindiMessage.replace(" ", "+");
Util.sendSMS(hindiMessage, hindiMobileNos);

Below is the code that sends the sms

    String url="http://sms.sendonlinesms.com/sendsmsv2.asp?user=****&password=*******&sender=*****&text="+message+"&PhoneNumber="+mobilenos+"&unicode=1";       

    URLEncoder.encode(url,"UTF8");

    URL myURL=new URL(url);

    URLConnection yc = myURL.openConnection();

Update: I have tried the following code as well

 URI uri=null;
    try {
        uri = new URI(
                "http", 
                "sms.sendonlinesms.com", 
                "/sendsmsv2.asp",
                "user=****&password=******&sender=70025&text="+message+"&PhoneNumber="+mobilenos+"&unicode=1",null);


    } catch (URISyntaxException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    URL myURL=uri.toURL();


    URLConnection yc = myURL.openConnection();

But it doesn't make any difference. Working fine on Mac but not on Windows. Using the application on mac, I am able to send sms in hindi, but using the application on windows the hindi characters are replaced by '?'

hemal237
  • 23
  • 7
  • possible duplicate of [HTTP URL Address Encoding in Java](http://stackoverflow.com/questions/724043/http-url-address-encoding-in-java) – nhahtdh Feb 12 '15 at 08:00
  • any idea as to why the above code seems to be working on a Mac but not on windows? – hemal237 Feb 16 '15 at 06:44
  • Would you please describe how it is not working? And which answer are you using? (Edit it in your post with the link to the answer so that people know what you have tried) Plus the version of the JRE on Mac and Windows? – nhahtdh Feb 16 '15 at 07:04
  • When I am sending sms in Hindi from the application running on mac, the sms are sent in hindi properly. But when I sent it from application running on windows, all characters are replaced by '?' I am updating the question with the code I tried from the link you provided. Both are on the same Java Version. Version 7 Update 60 – hemal237 Feb 16 '15 at 07:43
  • Do you use `uri.toASCIIString();`? Can't see that in your code. – nhahtdh Feb 16 '15 at 07:53
  • I am using uri.toUrl(). I have updated the code. – hemal237 Feb 16 '15 at 08:10
  • Have you check out the edits of the accepted answer and try that method? – nhahtdh Feb 16 '15 at 08:11
  • I found one other solution which worked. Explicitly setting the file encoding through code. System.setProperty("file.encoding","UTF-8") – hemal237 Feb 17 '15 at 05:49

0 Answers0