K
K
kator2019-09-06 16:50:34
Character encoding
kator, 2019-09-06 16:50:34

How to change request encoding in Node.js?

I am writing a parser for one torrent tracker.

  1. The user enters the search word in the browser.
  2. Node.js receives it, encodes it, and after forming a string, makes a request like this
    `http://trackername.org/forum/portal.php?word=${whatSearch}`
    .
  3. I am getting an html page and parsing it.

The problem is that that site uses the windows-1251 encoding, so the search only works with Latin, but not with Cyrillic (html is returned to me, but as a result of the search "Nothing was found").
I tried changing the encoding with iconv:
const whatSearch = iconv.encode(searchWord, 'win1251')
and send in a POST request both as a buffer and as a string. This gave a result, but the return is not at all what is needed (I am writing "Game of Thrones", but finds the book "Humpbacked Horse").
At the same time, everything works as it should in the terminal via cURL, even without the --data-urlencode.
How can I achieve the same in node?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question