如何以 win1251 字符集发送以下查询?
var getData = querystring.stringify({
type: "тест", note: "тест1"
}),
options = {
host: config.host,
path: config.path + '?' + getData,
method: 'GET'
};
http.request(options, function (res) {...}).end();
最佳答案
我认为这个片段可以帮助你
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();
}
});
更新 1
好的,我想找到一些有用的东西:)
您可以像这样使用上述实用程序
// 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'
关于javascript - Node.js:以 win1251 字符集发送 http 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32756501/