[英]Send http request multiple times in node.js
I'm trying to send the same http request multiple times.我正在尝试多次发送相同的 http 请求。 I just put the request in a loop, but when I run the code it shows the response 1 time.
我只是将请求放入循环中,但是当我运行代码时,它会显示响应 1 次。
const req = https.request(options, res => {
console.log(`statusCode: ${res.statusCode} ${res.statusMessage}`)
res.on('data', d => {
process.stdout.write(d)
})
})
for(i=0; i<3; i++){
req.write(data)
}
You should put the request inside the for loop:您应该将请求放入 for 循环中:
for(i=0; i < 3; i++){
const req = https.request(options, res => {
console.log(`statusCode: ${res.statusCode} ${res.statusMessage}`)
res.on('data', d => {
process.stdout.write(d)
})
});
req.write(data);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.