Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

171
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!