Page 1 of 1

JSON with special characters

Posted: Tue Feb 26, 2019 10:52 am
by mart3223
Hi All,

In my last Topic I was building a POST to a API. That is working fine right now with normal characters, the specials like "é" and "ë" are a problem right now. If I post this JSON with Postman everything is working fine:

Code: Select all

{"parcel":{"address":"Kattegat 18","city":"Groningen","company_name":"Tëst ","country":"NL","email":"support@none.nl","name":"Tést","order_number":"1234","parcel_items":[{"description":"BOEKEN","quantity":1,"sku":"97890828","value":"0","weight":"1"}],"postal_code":"9723JP","sender_address":57138,"shipment":{"id":492},"telephone":""}}
If I use the same JSON in Enfocus Switch and make a POST I get a empty response, no error nothing. The header I use "Content-Type:application/json" does someone have a idea what i'm doeing wrong?

Kind regards, Martijn

Re: JSON with special characters

Posted: Wed Feb 27, 2019 3:48 pm
by gabrielp
Curious -- does your web server/API get the request? Is it returning an empty response? Or is the request not even getting there?

Re: JSON with special characters

Posted: Wed Feb 27, 2019 4:08 pm
by mart3223
gabrielp wrote: Wed Feb 27, 2019 3:48 pm Curious -- does your web server/API get the request? Is it returning an empty response? Or is the request not even getting there?
Yes, it is returning a empty response. No error. If I use a JSON without special characters everything is working fine.

Re: JSON with special characters

Posted: Wed Feb 27, 2019 4:19 pm
by sander
mart3223 wrote: Tue Feb 26, 2019 10:52 am If I use the same JSON in Enfocus Switch
Could be a encoding issue. How do you create your json on the Switch server, and how do you post?

e.g. If you create your json via FileWrite try using UTF-8: File.write(json, jsonBody,'UTF-8')

Re: JSON with special characters

Posted: Wed Feb 27, 2019 5:20 pm
by mart3223
We use the app "Make JSON" and the POST function in Enfocus. I have add some screenshots.

The setting of the POST (HTTP reuest app)
Schermafbeelding 2019-02-27 om 17.18.41.png
Schermafbeelding 2019-02-27 om 17.18.41.png (24.73 KiB) Viewed 16371 times
The JSON of the app "Make JSON"
aa
aa
Schermafbeelding 2019-02-27 om 17.18.56.png (60.42 KiB) Viewed 16371 times

Re: JSON with special characters

Posted: Wed Feb 27, 2019 5:25 pm
by sander
Ouch, you posted in scripting. I’m not sure about these 3rd party apps. Do you have the scripting module?

Re: JSON with special characters

Posted: Wed Feb 27, 2019 6:08 pm
by sander
Now I’m thinking of it, try this header, might work:
Content-Type: application/json;charset=utf-8

Re: JSON with special characters

Posted: Thu Feb 28, 2019 12:32 pm
by mart3223
I don'y have the scripting module. I have tested with the header "Content-Type: application/json;charset=utf-8" but that doesn't change anything. Can it be a bug in Switch?

Re: JSON with special characters

Posted: Thu Feb 28, 2019 4:52 pm
by gabrielp
mart3223 wrote: Wed Feb 27, 2019 4:08 pm
gabrielp wrote: Wed Feb 27, 2019 3:48 pm Curious -- does your web server/API get the request? Is it returning an empty response? Or is the request not even getting there?
Yes, it is returning a empty response. No error. If I use a JSON without special characters everything is working fine.
Can you confirm that with the logs from the API server? You could log out the request body received by the API server and see what Switch is doing to the payload.