How to make UTF-8 in a promise request?

I made a request with Request-Promise using umlauts after the request:

var file = rp({uri: serviceURL, encoding: 'utf8'}).forEach(function (polizeistelle) {
    console.log(polizeistelle)
}

In the console log, it says "pr si" instead of "präsi"

thanks for the help

+4
source share
1 answer

This is because serviceURLutf8 does not deliver. It utf-8does not convert to utf8, but simply says to interpret the answer as utf8.

You have to use

rp({uri: serviceURL, encoding: 'latin1'})

to read the answer correctly and then convert it to utf8 if you need to.

+6
source

Source: https://habr.com/ru/post/1671513/


All Articles