11

I am having issue with push utf8 encode message using Parse Rest, here is my body

{"where":{"$and":[{"email":{"$in":["phaxxx@gmail.com","nhungxxx@gmail.com"]}},{"deviceType":{"$in":["ios"]}}]},"data":{"alert":"TEST: Giảm 40% Khi Mua Sách Harry Potter","sound":"default","page_type":"cms_key","page_value":"harry-potter"}}

Does anyone know how to encode utf8 message?

enter image description here

Thang Pham
  • 38,125
  • 75
  • 201
  • 285
  • are u sure that what u see is not a charsets def problem on the device that u show the screendump of? parseServer and mongoDB backing may both handle utf8 correctly but the handset is using ISO when the bytes provided by backend are using utf8? – Robert Rowntree May 12 '17 at 19:04
  • I am sure that my phone is not having character set problem. I regularly having notifications from other apps in Vietnamese language. – Thang Pham May 13 '17 at 03:16
  • 3
    Thang, what do you use as your REST-client when you send notifications? Are you sure that there is no issues with `JSON` encoding in that part of your pipeline? – SergGr May 13 '17 at 03:50
  • 1
    @SergGr: Thank you. That is the problem. I resolve the issue using solution here https://stackoverflow.com/questions/15322002/how-to-send-string-by-http-post-in-utf-8 or https://stackoverflow.com/questions/8964291/sending-utf8-contents-with-post-method-to-server-in-android-using-httpclient as my rest client is in java – Thang Pham May 24 '17 at 08:36

1 Answers1

2

Javascript code:

public bool SendPushNotification(string jsonContent)
{
...

    request.Headers.Add("X-Parse-Application-Id", appId);
    request.Headers.Add("X-Parse-REST-API-KEY", restApiKey);

    System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
    Byte[] byteArray = encoding.GetBytes(jsonContent);

...
}
Jadav Bheda
  • 5,031
  • 1
  • 30
  • 28