Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make UTF-8 in request-promise?

Tags:

node.js

utf-8

I made a request with Request-Promise with 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 help

like image 784
leona Avatar asked Mar 05 '17 13:03

leona


1 Answers

This is because the serviceURL is not delivering utf8. Here utf-8 is not converting to utf8, but merely tells to interpret the response as utf8.

You should use

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

to read the response correctly, and convert it to utf8 afterwards, if you need to.

like image 103
Lorenz Meyer Avatar answered Sep 21 '22 22:09

Lorenz Meyer