Hi, I am getting HTTP status code 400: Bad request (or 'Malformed request string' according to Pushwoosh documentation) when I try to send a push with content containing special symbols like éëïö. I am using Remote API, following your Java example code. Could you advise?

asked 15 Jul '14, 13:29
ikrumov's gravatar image

ikrumov
1112

Hello,

Could you please send us the whole createMessage request that fails to work? Special symbols shouldn't cause any issues with creating a notification.

Aside from that, please note that our API supports non-ASCII symbols only in the "\uXXXX" format, so we generally recommend to use the following code:

var dataString = JSON.stringify(data).replace(/[\u0080-\uFFFF]/g, function(m) { return "\u" + ("0000" + m.charCodeAt(0).toString(16)).slice(-4); });

(16 Jul '14, 08:06) Dmitry Dyudeev Dmitry%20%20Dyudeev's gravatar image

Here is the request:

 {
      "request": {
        "application": "XXXXX-XXXXX",
        "notifications": [
          {
            "apns_trim_content": 1,
            "conditions": [
              [
                "accountId",
                "EQ",
                4
              ],
              [
                "userId",
                "EQ",
                4
              ]
            ],
            "content": "tester@gmail.com : special characters: \u00f6\u00f6\u00fc\u00fc\u00f3\u00f3\r\n",
            "ios_badges": 1,
            "send_date": "now",
            "data": {
              "caseId": 706,
              "caseIdStr": "CVJ-39730"
            },
            "platforms": [
              1,
              3
            ]
          },
          {
            "apns_trim_content": 1,
            "conditions": [
              [
                "accountId",
                "EQ",
                4
              ],
              [
                "userId",
                "EQ",
                118
              ]
            ],
            "content": "tester@gmail.com : special characters: \u00f6\u00f6\u00fc\u00fc\u00f3\u00f3\r\n",
            "ios_badges": 1,
            "send_date": "now",
            "data": {
              "caseId": 706,
              "caseIdStr": "CVJ-39730"
            },
            "platforms": [
              1,
              3
            ]
          },
          {
            "apns_trim_content": 1,
            "conditions": [
              [
                "accountId",
                "EQ",
                4
              ],
              [
                "userId",
                "EQ",
                123
              ]
            ],
            "content": "tester@gmail.com : special characters: \u00f6\u00f6\u00fc\u00fc\u00f3\u00f3\r\n",
            "ios_badges": 1,
            "send_date": "now",
            "data": {
              "caseId": 706,
              "caseIdStr": "CVJ-39730"
            },
            "platforms": [
              1,
              3
            ]
          },
          {
            "apns_trim_content": 1,
            "conditions": [
              [
                "accountId",
                "EQ",
                4
              ],
              [
                "userId",
                "EQ",
                132
              ]
            ],
            "content": "tester@gmail.com : special characters: \u00f6\u00f6\u00fc\u00fc\u00f3\u00f3\r\n",
            "ios_badges": 1,
            "send_date": "now",
            "data": {
              "caseId": 706,
              "caseIdStr": "CVJ-39730"
            },
            "platforms": [
              1,
              3
            ]
          }
        ],
        "auth": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
      }
    }
(16 Jul '14, 08:35) ikrumov ikrumov's gravatar image

The strange thing is that we have just tested the request you provided, and it worked absolutely fine. You can see latest pushes on our demo account (username: demo, password: pushwoosh). Could you please double check whether this is the request that fails to work?

(16 Jul '14, 09:45) Dmitry Dyudeev Dmitry%20%20Dyudeev's gravatar image

It is. I only changed "auth", application code and the content of the message to include "tester@gmail.com" instead of a real address. I verified and the email change is not the problem. The request is sent to "https://cp.pushwoosh.com/json/1.3/createMessage"

Other requests that do not include special characters succeed.

(16 Jul '14, 10:21) ikrumov ikrumov's gravatar image

Hi, I'm ikrumov's college and we've solved the problem.

We copied your sample code here (Java)

http://www.pushwoosh.com/programming-push-notification/pushwoosh-push-notification-remote-api/#PushserviceAPI-JavaSample

and this approach caused our Linux server not to encode the request properly. We solved the problem by using HttpClient. This is how we finally coded the request

Client client = Client.create();
        client.setConnectTimeout(30 * 1000);
        client.setReadTimeout(50 * 1000);
        WebResource webResource = client.resource(requestUrl);

        ClientResponse response = webResource.accept(MediaType.APPLICATION_JSON_TYPE).post(ClientResponse.class, requestData.toString());

        InputStream in = response.getEntityInputStream();
        ByteArrayOutputStream out = new ByteArrayOutputStream();

        String jsonSrc = null;
        try {
            if (in.available() > 0) {
                ReaderWriter.writeTo(in, out);

                byte[] requestEntity = out.toByteArray();
                jsonSrc = new String(requestEntity, Charset.forName("UTF-8"));
            }
        } catch (IOException ex) {
            throw new ContainerException(ex);
        }

        if(jsonSrc == null || jsonSrc.isEmpty()) {
            return null;
        }
        return new JSONObject(jsonSrc);

I hope this helps other people who has similar problem

permanent link
answered 17 Jul '14, 14:48
chrisn's gravatar image

chrisn
212

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×141
×91
×83

question asked: 15 Jul '14, 13:29

question was seen: 2,918 times

last updated: 17 Jul '14, 14:48