X
X
xenonhammer2020-06-30 01:06:36
JavaScript
xenonhammer, 2020-06-30 01:06:36

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())

So:
axios.get(url,  {headers: {'Accept': 'application/json;charsrt: utf-8'}})
    .then(response => iconv.encode(iconv.decode(Buffer.from(response.data), 'windows-1251'), "utf8").toString())

And many more options, and still does not work. Help me understand what I'm missing

Answer the question

In order to leave comments, you need to log in

1 answer(s)
X
xenonhammer, 2020-06-30
@xenonhammer

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 question

Ask a Question

731 491 924 answers to any question