W
W
war762017-03-28 22:57:32
JavaScript
war76, 2017-03-28 22:57:32

How to specify encoding on nodejs in post request?

Good day I ran into a small problem, I send an ajax request from the client to the server, data of the form "a='Cyrillic'&b=' More
Cyrillic'" it is necessary to make that the server recognizes Russian characters? When sending a file from the server, I give utf-8 in the header

response.writeHead(200, {"Content-Type": `text/${textType}; charset=UTF-8`});

At the html page itself in meta - also utf-8
I get data from the post request:
var formidable = require('formidable');
var form = new formidable.IncomingForm();
function (request, response) {
   ....
         form.parse(request, function (err, fields, files) {
            fields.a//Кракозябра
         }
   ....       
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton, 2017-03-28
@pekc83

It is not entirely clear what "krakozyabra" is in this case. I would venture to suggest that this is percent-encoding and in this case it will save you:form.type = 'urlencoded';

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question