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

236
Visualizações
Not getting response with http GET call in prortactor

I am calling a GET api in my automation suite but not getting response back. Same API works from postman. I have plenty of console.log which are not getting printed. There are no errors too. Below is the snippet.


        var deferred = protractor.promise.defer();
        var options = {
            method: "GET",
            hostname: hostname,
            port: 8080,
            path: '/v1/fis/'+fiId+'/businessCustomers/'+userAuthId+'/approvals',
            headers: {
                'authorization': 'testclient',
                'content-type': 'application/json',
                'accept': 'application/json',
            }
        };
    
        var req = http.request(options, function (response) {
            browser.sleep(1000);
            console.log('headers are:', options);
            console.log('hostname is: ', hostname);
            browser.sleep(1000);
            console.log('STATUS for approval API : ' + res.statusCode);
            var chunks = [];

            response.on("data", function (chunk) {
                console.log('in chunk block::');
                chunks.push(chunk);
            });

            response.on("end", function () {
                var body = Buffer.concat(chunks);
                var finaljson = JSON.parse(body.toString());
                console.log('finaljson is:****', finaljson);
                successCallBack(finaljson.SuccessResponse);
            });
        });

        req.end();
        return deferred.promise;

    };```


Any insights will be helpful. TIA!
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Try something like this instead. Should work better. I left out your console.log messages for simplicity but you can easily add them in where you need.

function myFunction() {
  return new Promise(resolve, reject) {
    const options = {
        method: "GET",
        hostname: hostname,
        port: 8080,
        path: '/v1/fis/'+fiId+'/businessCustomers/'+userAuthId+'/approvals',
        headers: {
            'authorization': 'testclient',
            'content-type': 'application/json',
            'accept': 'application/json',
        }
    };

    http.get(options, (res) => {
      let rawData = '';
      res.on('data', (chunk) => { rawData += chunk; });
      res.on('end', () => {
        try {
          const finaljson = JSON.parse(rawData);
          resolve(finaljson.SuccessResponse);
        } catch (e) {
          reject(e.message);
        }
      });

    }).on('error', (e) => {
      reject(e);
    });
  }
}

And then you would just call it using myFunction().then((successResponse) => { // do stuff })

about 4 years ago · Juan Pablo Isaza 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