Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.js: Send http request in win1251 charset

How can I send the following query in win1251 charset?

var getData = querystring.stringify({
        type: "тест", note: "тест1"
    }),
    options = {
        host: config.host,
        path: config.path + '?' + getData,
        method: 'GET'
    };

http.request(options, function (res) {...}).end();
like image 482
ollazarev Avatar asked Sep 24 '15 08:09

ollazarev


1 Answers

I think this snippet can help you

request({ 
uri: website_url,
method: 'GET',
encoding: 'binary'
}, function (error, response, body) {
    body = new Buffer(body, 'binary');
    conv = new iconv.Iconv('windows-1251', 'utf8');
    body = conv.convert(body).toString();
     }
});

Update 1

OK, i think find something useful :)

Please check out this link

You can use above utility like this

// Suppose gbkEncodeURIComponent function already exists,
// it can encode string with `gbk` encoding
querystring.stringify({ w: '中文', foo: 'bar' }, null, null,
  { encodeURIComponent: win2unicode })
// returns
'w=%D6%D0%CE%C4&foo=bar'
like image 193
Alireza Davoodi Avatar answered Oct 13 '22 00:10

Alireza Davoodi