10-30-2023 08:58 AM
Hello all! Hoping for some helpful suggestions or insight regarding an issue we're facing with the new HTTP Client snap.
We're sending a POST request with a JSON body. Within the body are street addresses, and some addresses contain diacritical marks/accents. An example would be "Houssières".
We're supplying the body ($body) from an input Mapper into the snap as a raw entity, with the Content-Type header set to application/json:
I can't supply the full input body as it contains PII unfortunately, but the street address is supplied within the body like so. You can see the accent mark in question:
On debug, the snap parses the input body into a string labeled "requestString" within the response body, and within the string the accented character is shown as an unrecognized character:
The encoding issue is causing the endpoint we're POSTing to to respond with a 400:
So, is there some way I can combat this/force the snap to correctly encode similar strings within the request body? Maybe via JS within the raw entity in the snap, somehow? Anything I'm overlooking here that someone else has caught?
For context this isn't an issue we've faced with the older REST POST snap, but we like the extended functionality of the HTTP Client snap, and would prefer to use it (if feasible).
Thank you!
Solved! Go to Solution.
10-30-2023 09:22 AM - edited 10-30-2023 09:22 AM
UPDATE: I seem to have already fixed my own issue, hopefully this helps someone however if they make the same mistake I did.
My Content-Type header in my request wasn't specifying UTF-8 for encoding purposes, so I updated it to do so:
I assume the REST POST snap might have been defaulting to UTF-8 which is why it worked for me even though I was only supplying "application/json" without the charset, and in comparison the HTTP Client snap does not (?) I'm unclear. In any case, easy solution.
10-30-2023 09:22 AM - edited 10-30-2023 09:22 AM
UPDATE: I seem to have already fixed my own issue, hopefully this helps someone however if they make the same mistake I did.
My Content-Type header in my request wasn't specifying UTF-8 for encoding purposes, so I updated it to do so:
I assume the REST POST snap might have been defaulting to UTF-8 which is why it worked for me even though I was only supplying "application/json" without the charset, and in comparison the HTTP Client snap does not (?) I'm unclear. In any case, easy solution.