0

我正在尝试编写一个 node.js 脚本,如下所示

var https = require('https');
var options = {
  hostname: 'https://172.16.2.51',
  port: 9090,
  path: '/vm/list',
  method: 'GET',                
};

var req = https.request(options, function(res) {
  res.on('data', function(d) {
    process.stdout.write(d);
  });
});

req.end();
req.on('error', function(e) {
  console.error(e);
});

当我运行脚本时,我收到此错误:

{ [Error: getaddrinfo ENOENT] code: 'ENOTFOUND', errno: 'ENOTFOUND', syscall: 'getaddrinfo' }
4

1 回答 1

3

hostname属性options应该是IP地址或域名。在您的示例中,摆脱协议。所以改变这个:

var options = {
  hostname: 'https://172.16.2.51',
  port: 9090,
  path: '/vm/list',
  method: 'GET'
};

对此:

var options = {
  hostname: '172.16.2.51',
  port: 9090,
  path: '/vm/list',
  method: 'GET'
};
于 2013-10-31T05:54:31.060 回答