Set encoding in ballerina.io for HTTP GET response (ISO-8859-1 )

218 Views Asked by At

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

2

There are 2 best solutions below

0
On

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");
1
On

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.