gpt4 book ai didi

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

转载 作者:IT老高 更新时间:2023-10-28 23:26:05 27 4
gpt4 key购买 nike

如何以 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com