0

I have to send a post request with a body containing russian characters to a service which seems to only accept win1251 encoding. I am doing this in node.js using the request module.

This is how I am sending the request

var rawbody = "i1=&i2=&i3=" + query + "&i4=&i5=&i8="; 

var options = {
    url: this.initiate_endpoint,
    jar: this.session,
    cert: this.fs.readFileSync('resources/r.crt.pem', 'utf-8'),
    key: this.fs.readFileSync('resources/r.key.pem', 'utf-8'),
    timeout: 20000,
    headers: {
        'Content-Type': 'application/x-www-form-urlencoded'
    },
    body: rawbody
};
let cookie = this.session;

request.post(options,
    function (error, response, body) {
        if( error ) {
            callback(cookie, error);
        }
        else if( response.statusCode !== 200 ) {
            callback(cookie, 'Responded with status code: ' + response.statusCode);
        }
        else {
            callback(cookie, false);
        }
 });

Whenever the query variable is containing russian letters the request will fail.

For example:

var query = 'Путин';

So my questions are how to actually convert the encoding from the query variable to win1251 and furthermore how to set the encoding of the actual raw postbody, because I think those two things could be the cause of the issue.

Jakob Abfalter
  • 4,980
  • 17
  • 54
  • 94

0 Answers0