D
D
Denis_13342021-03-01 23:30:12
Node.js
Denis_1334, 2021-03-01 23:30:12

Is it possible to make a request multiple times with a single http.ClientRequest?

The request will be sent only 1 time, if you re -call httpRequest()in setInterval(), then it
http.ClientRequestwill be re-generated. Is it possible to use http.ClientRequest.write()many times for one object? To reduce the load, since the logic will be more complicated, there will be more handlers, and so on. Perhaps the question is very stupid, but still.

const options = {
  hostname: '127.0.0.1',
  port:80,
  method:'POST'
}

const callback = (res) => {
  res.on('data', (chunk) => {
    console.log(`Body: ${chunk}`)
  })
}
const req = http.request(options, callback)	
setInterval(() => {	
  req.write("")
}, 1000)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Lynn "Coffee Man", 2021-03-02
@Lynn

It is forbidden. One request - one object.
But this is not the place where you will have a performance problem.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question