0

I'm am working with bulk SMS application. It works fine, but when I send a message with Unicode characters, my mobile shows it as ????????.

I am using a XML file that contains URL, numbers and message body.

The code I have is this:

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL);
request.Method = "POST";
ASCIIEncoding encoding = new ASCIIEncoding();
byte[] byteArray = Encoding.UTF8.GetBytes(xml);
string text = Encoding.UTF8.GetString(byteArray);
request.ContentType = "text/xml; encoding='utf-8'";

request.UserAgent = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome / 41.0.2228.0 Safari / 537.36";
request.Accept = "text/xml,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";

request.ContentLength = byteArray.Length;
Stream dataStream = request.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
WebResponse response = (HttpWebResponse)request.GetResponse();

if (response.ContentLength > 0)
{
    Console.WriteLine(((HttpWebResponse)response).StatusDescription);
    dataStream = response.GetResponseStream();

    using (StreamReader reader = new StreamReader(dataStream))
    {
        returnValue = reader.ReadToEnd();
    }
}
else
{
    returnValue = "ERROR" + " " + "No Response From Jasmin";
}

Console.WriteLine(returnValue);
dataStream.Close();
response.Close();

Hope you guys give me a solution to this?

miken32
  • 42,008
  • 16
  • 111
  • 154

1 Answers1

0

SMS uses the UCS-2 character set for unicode characters (16 bits per char, so your maximum length is halved). If your source string isn't ASCII compatible then you need to convert to UCS-2. For how to do that, see Convert to UCS2

Steve Todd
  • 1,250
  • 6
  • 13