0

I'm writing a simple API request to Roblox so I can retrieve the X-CSRF-TOKEN to do POST requests. The issue I'm facing is "Error: socket hang up".

I tried to just run the link in my browser and it displays a JSON table, but when I do the request through node.js it errors out.

const https = require("https")

const options = {
    hostname: "groups.roblox.com",
    path: "/v1/groups/5307563",
    method: "GET",
    headers: {
        'Content-Type': 'application/json',
        'Accept': 'application/json',
        'Cookie': '.ROBLOSECURITY=' + cookie
    }
}

const request = https.request(options, res => {
    
    res.on('data', data => {
       console.log("data received")
    })

});

request.on('error', error => {
    console.log(error)
})
Derpy
  • 3
  • 1
  • Have any of the other answers about this error been helpful? Like this one? https://stackoverflow.com/questions/16995184/nodejs-what-does-socket-hang-up-actually-mean – Kylaaa May 10 '21 at 13:52

1 Answers1

0

You need to end the request with request.end().


const https = require("https")

const options = {
    hostname: "groups.roblox.com",
    path: "/v1/groups/5307563",
    method: "GET",
    headers: {
        'Content-Type': 'application/json',
        'Accept': 'application/json',
        'Cookie': '.ROBLOSECURITY=' + cookie
    }
}

const request = https.request(options, res => {
    
    res.on('data', data => {
       console.log("data received")
    })

});

request.on('error', error => {
    console.log(error)
})
request.end()

user8385393
  • 104
  • 1
  • 9