用node.js的https模块 老是报错信息为
getaddrinfo ENOTFOUND 后面就是我的host
而且path的值也没有拼接上去
请问这个怎么弄?下面是代码。
const postData = querystring.stringify({
action: "getAuth", //获取验证串
key: "rcJ27M9jMqyvnH5d7xVCO8KtS2ELtpbT8xVDXQQtpiyNDeTrIMcXqK4O911N7jd9", //开发者的 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(`状态码: ${res.statusCode}`);
console.log(`响应头: ${JSON.stringify(res.headers)}`);
res.setEncoding('utf8');
res.on('data', (chunk) => {
console.log(`响应主体: ${chunk}`);
html+=chunk
});
res.on('end', () => {
console.log(html);
});
});
req.on('error', (e) => {
console.error(`请求遇到问题: ${e.message}`);
});
// 写入数据到请求主体
req.write(postData);
req.end();