![](/img/trans.png)
[英]How to convert utf-8 string to urlencoded win1251 in javascript
[英]Node.js: Send http request in win1251 charset
如何在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();
我认为这个片段可以帮到你
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'
服务器是否真的在URL的查询部分接受win1251?
但是这里有一些与您的问题相符的SO答案:
在Node.js中从Windows-1251转换为UTF-8
这减少了使用这些库中的任何一个,你也应该在npm上找到它们。
https://github.com/bnoordhuis/node-iconv
要么
https://github.com/ashtuchkin/iconv-lite
迈克尔
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.