簡體   English   中英

Node.js:在win1251字符集中發送http請求

[英]Node.js: Send http request in win1251 charset

如何在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();

我認為這個片段可以幫到你

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?

我應該假設URL中的編碼字符是什么字符集?

但是這里有一些與您的問題相符的SO答案:

在Node.js中從Windows-1251轉換為UTF-8

nodejs http響應編碼

這減少了使用這些庫中的任何一個,你也應該在npm上找到它們。

https://github.com/bnoordhuis/node-iconv

要么

https://github.com/ashtuchkin/iconv-lite

邁克爾

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM