Http requests samples
Last active
March 6, 2024 23:23
-
-
Save OsvaldoFrias/3134ad78ac2343f5efebc4897764d0d9 to your computer and use it in GitHub Desktop.
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
// https://www.npmjs.com/package/request-digest | |
const securos = require('securos'); | |
var digestRequest = require('request-digest')('root', '1iss!1iss!'); | |
securos.connect(async function (core) { | |
core.registerEventHandler("CAM", "*", "VCA_EVENT", eventSender); | |
async function eventSender(e) { | |
//console.log(e); | |
const grabber = await core.getObject('CAM', e.sourceId); | |
if (e.params.description == "NN fallen person detector") { | |
console.log("test"); | |
core.doReact("VNS", "1", "PLAY_WAV", { file: '\\Wav\\fallen_person.mp3' }); | |
digestRequest.request({ | |
host: 'http://192.168.0.171', | |
path: '/axis-cgi/playclip.cgi?location=fallen_person.mp3&repeat=0&volume=100', | |
port: 80, | |
method: 'GET', | |
headers: { | |
'Custom-Header': 'OneValue', | |
'Other-Custom-Header': 'OtherValue' | |
} | |
}, function (error, response, body) { | |
if (error) { | |
throw error; | |
} | |
console.log(body); | |
}); | |
} | |
} | |
}) |
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
const http = require('http'); | |
const options = { | |
host: "127.0.0.1", | |
port: "3001", | |
path: '/', | |
method: "POST", | |
headers: { | |
"Authorization": "Basic cG9jY2VzYTpjb29wZWFsaWFuemE=", | |
"Cache-Control": "no-cache", | |
'Content-Type': 'application/json', | |
'Content-Length': myJSONObject.length | |
} | |
}; | |
const req = http.request(options, (res) => { | |
let data = ''; | |
console.log('Status Code:', res.statusCode); | |
res.on('data', (chunk) => { | |
data += chunk; | |
}); | |
res.on('end', () => { | |
console.log('Body: ', JSON.parse(data)); | |
}); | |
}).on("error", (err) => { | |
console.log("Error: ", err.message); | |
}); | |
req.write(myJSONObject); | |
req.end(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment