Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

172
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda