Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

249
Visualizações
Curl and Postman giving different response?

I am writing API in node.js.

url http://localhost:8000/api/request?connId=19&timeout=8000

when I call above API from Postman then it takes 8 seconds to give the response. same as expected.

but when call this from curl it gives output instantly.

curl http://localhost:8000/api/request?connId=19&timeout=8000

Code is:

app.get('/api/request', ( req, res ) => {

    let timeoutID = null;   // return by setTimeout
    let starttime = null;   // time when request is begin
    const time = req.query.timeout;     // time send by client
    const connId = req.query.connId;    // id send by client

    // checking client data is valid or not
    if ( typeof(connId) !== undefined && typeof(time) !== undefined ) {

        starttime = new Date();     // get current time
        starttime = starttime.setMilliseconds(starttime.getMilliseconds()); // convert into millisecon
        // initiate setTimeout
        timeoutID = setTimeout(() => {
            // remove that element from global array which reqest has been complted
            removeByAttr(timeout, 'connId', connId);
            // res.send({ status: "ok"});       // send response

        }, time);
        // initiate setInterval
        const setInv = setInterval(() => {
            // check timeout [] conatin the current request
            const arrLength = timeout.length && timeout.filter(({ connId }) => req.query.connId === connId).length;

            if ( arrLength === 0 ) {
                res.send({ status: "ok"}); // send response
                clearInterval(setInv);      // clear/destroy current Interval
            }

        }, 80);

        // insert the current request into global [] timeout
        timeout.push({
            connId,
            time,
            timeoutID,
            starttime,
            'endtime': +starttime + +time
        });
    } 
});
about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

As I found from your code and curl tutorial that When you GET a endpoint with curl your command should be like this:

curl "http://localhost:8000/api/request?connId=19&timeout=8000"

Without double inverted comma in url, console.log(req.query) will result in { connId: '19' } which is causing the problem.

about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda