将值分配给节点js中的变量时面临问题

时间:2019-07-23 09:26:53

标签: node.js

HTTP请求输出的数据正在控制台中。我需要分配一个变量

const options = {
  hostname: 'abcdef',
  port: 443,
  path: '/xyz',
  method: 'GET',
  rejectUnauthorized: false,
  requestCert: true,
  agent: false
};

https.request(options, (res) => {
  res.on('data', (d) => {
    process.stdout.write(d);// this will print to the console
  });
}).on('error', (e) => {
  console.error(e);
}).end();

我是node.js的新手,请帮助我解决这个问题。

1 个答案:

答案 0 :(得分:1)

因为没有为sql = "select num_store, sum(gross_sales) as gross_sales from dtm.sales where day = " + input_date.strftime('%Y-%m-%d') + ... 设置encoding,所以其数据将显示为response。您需要Buffer从响应数据中获取字符串值