WebAPI handles Chinese Characters / Emoji

I'm writing a WebAPI which required to handle HTTP POST and the body will include Chinese characters and emoji.  I wrote a loop back test but I found that the WebAPI returns "?" when I use cURL to test.  Is there any example or best practice on how to handle those kind of characters? Pray tone1

a!localVariables(
  local!json: if(
    isnull(http!request.body),
    a!fromJson("{""hello"":""world 中文 😀""}"),
    a!fromJson(http!request.body)
  ),
  a!httpResponse(
    headers: {
      a!httpHeader(name: "Content-Type", value: "application/json")
    },
    body: a!toJson(local!json)
  )
)

% curl --location \
--request POST 'https://my.server.com/suite/webapi/LoopBack' \
--header 'Content-Type: application/json;charset=utf-8' \
--header 'Authorization: Bearer abc.def.ghi' \
--data-raw '{"hello":"world 中文 😀"}'

{"hello":"world ?? ?"}%

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Associate Developer

    Hi Daniel, I hope this might be useful for you to understand some context over

    This occurs when the Web API does not send an appropriate "Content-Type" header with a character set included, which the client system relies on to interpret the content sent by the Web API.

    And I would suggest to Explicitly specify the Content-Type header with the relevant character set in the SAIL code for the Web API using a!httpHeader in the headers parameter of the a!httpResponse

    For example, to correctly send JSON with the UTF-8-character set. 

    headers: {
      a!httpHeader(
        name: "Content-Type",
        value: "application/json; charset=utf-8"
      )
    }

Reply
  • 0
    Certified Associate Developer

    Hi Daniel, I hope this might be useful for you to understand some context over

    This occurs when the Web API does not send an appropriate "Content-Type" header with a character set included, which the client system relies on to interpret the content sent by the Web API.

    And I would suggest to Explicitly specify the Content-Type header with the relevant character set in the SAIL code for the Web API using a!httpHeader in the headers parameter of the a!httpResponse

    For example, to correctly send JSON with the UTF-8-character set. 

    headers: {
      a!httpHeader(
        name: "Content-Type",
        value: "application/json; charset=utf-8"
      )
    }

Children
No Data