R
R
Richard Hendrix2017-09-19 22:56:31
JavaScript
Richard Hendrix, 2017-09-19 22:56:31

How to specify encoding in request module in node.js?

All Cyrillic characters sent using the 'request' and 'http' modules end up as an incomprehensible cluster of Latin numbers and letters.
70f237fdd4c845978a5d6c73248fe582.png
I send it to api.vk, and the following comes up:
a6c231a52b7842e8910adf71242b63be.png
What exactly are the actions required to return the Slavic power to the script ?!

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Stockholm Syndrome, 2019-06-05
@StockholmSyndrome

func1() {
  return this.setJson();
}

async func2() {
  let q = await this.func1();
  return q;
}

V
Vladimir, 2019-06-05
@Casufi

https://m.habr.com/ru/company/mailru/blog/269465/

V
Vladlen Hellsite, 2017-09-20
@GeekT

I will offer a more modern version of vk-io .
In your version, you get a chunk, not a full string:

.on('response', (response) => {
   let body = '';
  response.on('data', (chunk) => {
     body += String(chunk);
  });
  response.on('end', () => {
     body = JSON.parse(body);

     console.log(body);
  });
})

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question