Javascript Node.js:在win1251字符集中发送http请求

Javascript Node.js:在win1251字符集中发送http请求,javascript,node.js,url-encoding,Javascript,Node.js,Url Encoding,如何在win1251字符集中发送以下查询 var getData = querystring.stringify({ type: "тест", note: "тест1" }), options = { host: config.host, path: config.path + '?' + getData, method: 'GET' }; http.request(options, function

如何在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'

服务器是否真的在URL的查询部分接受win1251

但以下是一些与您的问题相匹配的答案:

这将减少到使用这些库中的任何一个,您也可以在npm上找到它们

Michael

您不能“以特定字符集”发送任何内容。您只能将其编码到该字符集(二进制),然后以所选协议(二进制!)发送。然后,可以向接收服务器提供将正确字符集中的二进制文件解码为字符串的信息。你需要提供更多关于你的约束和期望结果的信息。