oll*_*rev 9 javascript url-encoding node.js
如何在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();
Run Code Online (Sandbox Code Playgroud)
我认为这个片段可以帮到你
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();
}
});
Run Code Online (Sandbox Code Playgroud)
更新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'
Run Code Online (Sandbox Code Playgroud)