NodeJS https.get with unicode string results in Ba

2019-08-09 01:56发布

Can someone help me debug the following code snippet? It queries the WikiMedia API with unicode characters, in this case Simplified Chinese.
The prooblem is that with the latest (0.12.6) node version (built from source) with options:

--with-intl=full-icu --download=all  

results in an empty body. Check the response to find Bad Request.
However, the same code snippet works fine with node version 0.10.25 (I think I got it from the Ubuntu package manager). Apperently older version have internationalisation support by default and newer ones do not.

How can I get the following code to work with the latest nodejs version?

// Generated by CoffeeScript 1.9.3
(function() {
  var GET, cmd, https, languageCode, options;

  https = require('https');

  GET = function(options, callback) {
    return https.get(options, function(response) {
      var body;
      body = '';
      response.on('data', function(data) {
        return body += data;
      });
      return response.on('end', function() {
        return callback(body, response);
      });
    });
  };

  languageCode = 'zh';

  cmd = '笔记本电脑';

  options = {
    host: languageCode + '.wikipedia.org',
    path: '/w/api.php?action=opensearch&search=' + cmd
  };

  GET(options, function(body, response) {
    return console.log(response);
  });

}).call(this);

1条回答
你好瞎i
2楼-- · 2019-08-09 02:19
登录 后发表回答