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

179
Visualizações
Make HTTP get request

I am trying to make a HTTP get request, but nothing is being returned as text. Here is my code

const http = require('http');
const ws = require('ws');
const wss = new ws.Server({noServer: true});
var XMLHttpRequest = require('xhr2');

function accept(req, res) {
    console.log("got request")
    wss.handleUpgrade(req, req.socket, Buffer.alloc(0), function(ws) {
        //party name, sockets on party, limit 2
        ws.on('message', function (msg) {
            var message = JSON.parse(msg.toString())
            if(message.type==='add') {
                //do later
            } else if(message.type==='start') {
                httpGetAsync('192.168.26.23', "/startRelay")
            } else if(message.type==='stop') {
                httpGetAsync('92.168.26.23', "/stopRelay")
            } else if(message.type==='status') {
                httpGetAsync('92.168.26.23', "/")
            }
        });
        ws.on('close', function () {
            console.log('closed')
        });
        ws.on('error', function(error){
            console.log('error - ' + JSON.stringify(error));
        });
    })
}

function httpGetAsync(theUrl, path) {
  var options = {
      host: theUrl,
      path: path,
      method: "GET",
  }
  callback = async function(response) {
      var str = ''
      response.on('data', function (chunk) {
        str += chunk;
      });
      response.on('end', function () {
          console.log(JSON.parse(str));
      });
  };
  http.request(options, callback).end(); 
}

http.createServer(accept).listen(3000);

Here is what 192.168.26.23 has in it (if you type it up from my wifi onto google, this is what shows - and this data is what I need to get in a string)

{"success":true,"ms_left":0,"relayStarted":false}
about 4 years ago · Juan Pablo Isaza
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