鍍金池/ 問答/HTML/ Node.js http 請(qǐng)求報(bào)錯(cuò)

Node.js http 請(qǐng)求報(bào)錯(cuò)

用node.js的https模塊 老是報(bào)錯(cuò)信息為
getaddrinfo ENOTFOUND 后面就是我的host
而且path的值也沒有拼接上去

請(qǐng)問這個(gè)怎么弄?下面是代碼。

const postData = querystring.stringify({
  action: "getAuth",                 //獲取驗(yàn)證串
  key: "rcJ27M9jMqyvnH5d7xVCO8KtS2ELtpbT8xVDXQQtpiyNDeTrIMcXqK4O911N7jd9",                 //開發(fā)者的 access key
  devices: ["5285dded85d52222262f4f0389985704"],  
  valid: 3600,           //單位秒,最大為 3600
  time: date
});

const options = {
  protocol: 'https:',
  host: 'https://storeauth.touchsprite.com',
  path: '/api/openapi',
  method: 'POST',
  headers: {
    'Content-Type': 'application/x-www-form-urlencoded',
    'Content-Length': Buffer.byteLength(postData)
  }
};


const req = https.request(options, (res) => {
  htm=""
  console.log(`狀態(tài)碼: ${res.statusCode}`);
  console.log(`響應(yīng)頭: ${JSON.stringify(res.headers)}`);
  res.setEncoding('utf8');
  res.on('data', (chunk) => {
    console.log(`響應(yīng)主體: ${chunk}`);
    html+=chunk
  });
  res.on('end', () => {
    console.log(html);
  });
});

req.on('error', (e) => {
  console.error(`請(qǐng)求遇到問題: ${e.message}`);
});

// 寫入數(shù)據(jù)到請(qǐng)求主體
req.write(postData);
req.end();
回答
編輯回答
葬愛
const options = {
  protocol: 'https:',
  host: 'storeauth.touchsprite.com',
  path: '/api/openapi',
  method: 'POST',
  headers: {
    'Content-Type': 'application/x-www-form-urlencoded',
    'Content-Length': Buffer.byteLength(postData)
  }
};
2017年11月1日 04:30