Umlauts broke on receipt of request

I am trying to request a web service that answers in plain text. There are often German umlauts in the text . In the received stream, the umlauts are broken. Any ideas what I'm doing wrong?

Regards, Thorsten

Here is a sample code:

var request = require('request'); var uri = <anUriWithUserId>; request(uri, {encoding: 'utf8','content-type': 'text/plain; charset=UTF-8'}, function (error, response, body) { console.log("encoding: " + response.headers['content-encoding']); console.log("type: " + response.headers['content-type']); console.log(body); }); 

And the answer is:

 encoding: undefined type: text/plain error=0 --- asin= name=Eistee detailname=Pfanner Der Gr ne Tee, Zitrone - Kaktusfeige, 2,0 l vendor=Hermann Pfanner Getr nke GmbH, Lauterach,  sterreich maincat=Getr nke, Alkohol 
0
source share
1 answer

When you set the encoding option in your request, you advise the request module to decode the response body using this encoding. This way you ignore the encoding used by the web service, which may or may not be utf-8. You need to find out what encoding the web service was used and use it.

Depending on how satisfied you are with the web service, you can also set the Accept-Charset: utf-8 header.

As your conclusion shows, the web service does not provide the encoding used in the Content-Type header, which is a bad habbit imho.

Sidenote: Content-Encoding is not for encoding, but for compression, gzip migh is a valid value for it.

0
source share

All Articles