Answer the question
In order to leave comments, you need to log in
How to decode windows-1251 using iconv-lite?
Unable to translate the response from a third-party server. The response itself in the headers is windows-1251 encoded. In php, everything was obviously decided
. Here, I don’t understand at all ... I tried it like this:
iconv("windows-1251", "UTF-8", $result)
axios.get(url, {headers: {'Accept': 'application/json;charsrt: utf-8'}})
.then(response => iconv.decode(Buffer.from(response.data), 'windows-1251').toString())
axios.get(url, {headers: {'Accept': 'application/json;charsrt: utf-8'}})
.then(response => iconv.encode(iconv.decode(Buffer.from(response.data), 'windows-1251'), "utf8").toString())
Answer the question
In order to leave comments, you need to log in
It turned out that the point is that you need to give axios the necessary parameters.
Solution:
axios.get(
url,
{
responseType: 'arraybuffer',
responseEncoding: 'binary'
})
.then(response => iconv.decode(Buffer.from(response.data), 'windows-1251'))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question