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();
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();
Share
asked Sep 24, 2015 at 8:13
ollazarevollazarev
1,1061 gold badge9 silver badges26 bronze badges
1
- You can not send anything "in a certain charset". You can only encode it in that charset (to binary) and then send it in the chosen protocol (as binary!). Then, the receiving server can be given information to decode the binary in the correct charset to a string. You need to provide more info about your given restraints and desired oute. – Igor Skoric Commented Jan 4, 2016 at 13:13
2 Answers
Reset to default 5I 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'
Does the server really accept win1251 in the query part of the URL?
What character set should I assume the encoded characters in a URL to be in?
But here are some SO answers that match your question:
Converting from Windows-1251 to UTF-8 in Node.js
nodejs http response encoding
Which reduce down to using either of these libraries, which you should also find on npm.
https://github./bnoordhuis/node-iconv
or
https://github./ashtuchkin/iconv-lite
Michael
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744880474a4598809.html
评论列表(0条)