0

I download several CSV files via HTTP endpoints and write them into a database. This works. But I noticed that parts of my response are wrongly encoded.

Example:

var response = endpoint->get("url");
io:println(response.getTextPayload().toString());

looks like this:

ZYR;ZYR;;Br�sse;Br�ssel;Br�ssel Railway;S;N;N;BE
ZYZ;ZYZ;;Brussl;Br�ssel;Br�ssel Railway;S;N;N;BE

The following letters are wrongly encoded äöüÄÖÜ (German letters).

Is it possible to set the correct encoding for the response. For example in ISO-8859-1?

Many greetings, Martin

Martin
  • 65
  • 3

2 Answers2

1

The getXXXPayload() functions use the charset given in the Content-type response header for the payload encoding.

Content-Type: [text/html; charset=utf-8]

Please check the Content-type response header, whether it contains the required charset or not.

Chamil E
  • 478
  • 3
  • 10
  • Many thanks for the answer. Unfortunately the server does not set a charset. When I execute the following command: log:printInfo("getContentType: "+ response.getHeader("Content-Type")); I get the following output: text/x-comma-separated-values Are there other ways to set the encoding? – Martin Sep 23 '20 at 15:35
0

Oh, my bad. Of course I can set the content-type afterwards.

response.setHeader("Content-Type", "text/x-comma-separated-values; charset=ISO-8859-1");
Martin
  • 65
  • 3