Web Connection
Text encoding confusion
Gravatar is a globally recognized avatar based on your email address. Text encoding confusion
  Carl Chambers
  All
  Nov 26, 2024 @ 03:52pm

I'm still having some mental block regarding text encoding.

I'm trying to provide non-English data in my API response, in this case Spanish.
Here's a sample part description ("Manómetro") in the Browse window (this table is queried by my API) looking as it should...

I have a test PRG that fetches the JSON from my API using wwHTTP, saves it to a file using StrToFile() and then displays it using MODIFY FILE. A snip of the result is below looking as expected.

But when I execute the same request using Postman, the "ó" character is replaced with a question mark and I don't know where the problem is.

I'm not terribly familiar with Postman and I've looked for a setting in Postman that looks like it might cause this but with no success.
Does anyone know what I'm missing or doing wrong?

Thanks,
Carl

Gravatar is a globally recognized avatar based on your email address. re: Text encoding confusion
  Rick Strahl
  Carl Chambers
  Nov 26, 2024 @ 04:22pm

The data returned has to be UTF-8 encoded. Postman fails because it can't render the special character because it's expecting UTF-8.

Make sure the API result is UTF-8 encoded. If you're using the Web Connection REST process it should do that automatically. If you're manually sending your JSON back make sure the serialized data is UTF-8 encoded (there are options on the serializer) and that the response is UTF-8 encoded (by default in Web Connection if you have a reasonably recent version).

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: Text encoding confusion
  Rick Strahl
  Carl Chambers
  Nov 26, 2024 @ 04:30pm

Most HTTP clients will automatically decode UTF-8 so it's kind of difficult to see the raw data that's going over the wire. The server sending the data should encode that special character into a two-character UTF-8 code.

You can look at the raw data with wwHttp by making sure to turn off UTF-8 decoding using:

oHttp.lDecodeUtf8 = .F.   && .T. by default

The string that comes back here should not have your accented character in it but the UTF-8 multi-character representation.

If it comes back with your accented character, then the content is not UTF-8 encoded and you need to make sure the request gets encoded on the server.

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: Text encoding confusion
  Carl Chambers
  Rick Strahl
  Nov 26, 2024 @ 08:06pm

Thanks for the explanation, Rick.
I have a better understanding of it now.

Carl

© 1996-2024