Created
January 24, 2018 05:13
-
-
Save thblckjkr/f3f06485d98077f2411e9eef0c6a54f1 to your computer and use it in GitHub Desktop.
Simply get on NodeJS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var options = { | |
host: this.blackbox.ip, | |
port: this.blackbox.port, | |
path: '/alive', | |
method: 'GET', | |
headers: { | |
'Accept': 'application/json', | |
'Accept-Encoding': 'gzip,deflate,sdch', | |
'Accept-Language': 'en-US,en;q=0.8' | |
} | |
}; | |
var str = ""; | |
var req = http.request(options, function (res) { | |
res.setEncoding('utf8'); | |
res.on('data', function (chunk) { | |
str += chunk; | |
}).on('end', function () { | |
var info = JSON.parse(str)[0]; | |
callback(info); | |
}); | |
}).on('error', function (err) { | |
callback(false); | |
}); | |
req.end(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment