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

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)

Ali*_*odi 5

我认为这个片段可以帮到你

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)

  • 我需要查询字符串必须在win1251中编码 (2认同)