javascript - Node.js:以 win1251 字符集发送 http 请求

标签 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 (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

好的,我想找到一些有用的东西:)

Please check out this link

您可以像这样使用上述实用程序

// 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/

相关文章:

javascript - 使用 Node.js 创建定期 Outlook 日历事件

node.js - 如何在 JSX 中使用 nodemon?

ruby - 如何使用具有特殊字符的用户名或密码解析 FTP URL?

javascript - 背面可见性在 IE11 中不起作用

javascript - 如何使用 jQuery 以与数组相同的顺序对 html 元素进行排序?

php - setTimeout 与 ajax 聊天

javascript - 如何导出node.js中请求生成的变量

javascript - div 固定在滚动的某个点

php - 克服非utf8 url编码

ios - Swift URL 字符串编码在 iOS 上崩溃?